Made a massive tweak to the findenemy function, so that the search does NOT slow the emulator down significantly.
local function enemygroupexists(num)
	local area = memory.readbyte(0x7E1700)
	local group = 0
	local x = 0
	local x2 = 0
	local val1 = 0
	local val2 = 0
	local val3 = 0
	local rollover = false
	local rollover2 = false
	local i = 0
	local j = 0
	
	if area == 0 then
	-- Earth world map
		
		
			val1 = bit.band(bit.rshift(memory.readbyte(0x7E1707),2), 0xF8)
			x = (bit.rshift(memory.readbyte(0x7E1706),5) + val1)  % 0x100
			val2 = bit.lshift(memory.readbyte(0x0ec542+x),3)
			
			for j = val2, val2+7 do
				if num == memory.readbyte(0xEC796+j) then
					group = 1
				end
				if memory.readbyte(0x7E1701)  > 0 then
					if num == (memory.readbyte(0xEC796+j)+0x100) then
						group = 1
					end
				end
			end
	
	elseif area == 1 then
		-- Underground world map
		
		
		
			val1 = bit.band(bit.rshift(memory.readbyte(0x7E1707),3),0xFC)
			x = bit.rshift(memory.readbyte(0x7E1706),5)
			x = (x + val1)  % 0x100
			val2 = bit.lshift(memory.readbyte(0x0ec582+x),3)
			
			
			for j = val2, val2+7 do
				if num == memory.readbyte(0xEC796+j) then
					group = 1
				end
				if memory.readbyte(0x7E1701)  > 0 then
					if num == (memory.readbyte(0xEC796+j)+0x100) then
						group = 1
					end
				end
			end
			
		
		
	elseif area == 2 then
	--Moon world map
		
		
			if memory.readbyte(0x7E1707) > 0x20 then
				x = 2
			end
			
			if memory.readbyte(0x7E1706) > 0x20 then
				x = x + 1
			end 
			
			val2 = memory.readbyte(0x0EC592 + x)
			val2 = bit.lshift(val2,3)
			
			for j = val2, val2+7 do
				if num == memory.readbyte(0xEC796+j) then
					group = 1
				end
				if memory.readbyte(0x7E1701)  > 0 then
					if num == (memory.readbyte(0xEC796+j)+0x100) then
						group = 1
					end
				end
			end		
			
		
		
	elseif area > 2 then
	
		
		--Dungeon
			val1 = memory.readbyte(0x7E1702)
			
			if memory.readbyte(0x7E1701) > 0 then
				val1 = val1 + 0x100
			end
			
			val2 = bit.lshift(memory.readbyte(0x0EC596+val1),3)	
			
			for j = val2, val2+7 do
				if num == memory.readbyte(0xEC816+j) then
					group = 1
				end
				if memory.readbyte(0x7E1701)  > 0 then
					if num == (memory.readbyte(0xEC796+j)+0x100) then
						group = 1
					end
				end
			end
			
		
		
	end
	
	return group
	
end
local function findenemy(e,x)
 
	local c = 0
	local i = 0
	local result  = ": "
	if enemygroupexists(e) == 0 then
		result = "(Enemy not present in area)"
		return result
	end
	
	while c ~= x  do
		
		if enemygroup(i) == e then
			c = c +1
		
			if c ~= x then
				result = result .. i .. ","
			else
				result = result .. i
			end
			
		end
		
		i = i + 1
		
		if i >= 500 and c == 0 then
			result = "(Enemy not present in next 500 battles)"
			c = x
		end
	end
  
	result = retrievegroup(e) .. " (" .. string.format("%X",e) .. ")" .. result
	return result
	
 end
It now checks to see if the group is present in one of the 8 possible battle groups, before actually searching at least the next 500 battles for that group.  (with slowdown only possibly present for rare groups, when it does exist in current area.)