I was testing Julia WebSockets and I found that they are much slower than the Python/Node equivalents. I wrote a test to send a ping and measure the time taken for a pong response from some crypto exchanges as an example. Julia consistently takes 50ms for the test below, whereas python takes 2-4 ms. Is this expected?
Julia:
using WebSockets
function main()
WebSockets.open("wss://wsaws.okex.com:8443/ws/v5/public") do ws
for i = 1:100
a = time_ns()
write(ws, "ping")
data, success = readguarded(ws)
b = time_ns()
println(String(data), " ", (b - a) / 1000000)
sleep(0.1)
end
end
end
main()
Equivalent Python:
import websockets
import asyncio
import time
async def main():
uri = "wss://wsaws.okex.com:8443/ws/v5/public"
async with websockets.connect(uri) as websocket:
msg = "hello"
for i in range(101):
a = time.time()
await websocket.send(msg)
x = await websocket.recv()
b = time.time()
print(b-a)
time.sleep(0.1)
asyncio.get_event_loop().run_until_complete(main())