test code with no btoa(), and interval = 0
function onInit(){ var ssid = "HGiga3"; var wifiOpts = {password:"20071203"}; var wifi = require("Wifi"); wifi.connect(ssid, wifiOpts, function(err){ console.log("connected? err=", err, "info=", wifi.getIP()); var WebSocket = require("ws"); var host = "192.168.1.9"; var ws = new WebSocket(host,{ path: '/', port: 5004, // default is 80 protocolVersion: 13, // websocket protocol version, default is 13 origin: 'Espruino', keepAlive: 60, }); ws.on('open', function() { console.log("connected"); //ws.send('hello, server'); var packet = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; var pktNum = 0; var ta = 0; var id = setInterval(function(){ var t1 = getTime(); ws.send(packet); pktNum ++; console.log("Packet NO.: " + pktNum + ", time used: " + (t2 = getTime() - t1) + "s"); ta += t2; if(pktNum >=101){ console.log("total time used: " + ta +"s"); clearInterval(id); } }, 0); }); }); }
result:
connected? err= null info= { "ip": "192.168.1.30", "netmask": "255.255.255.0", "gw": "192.168.1.1", "mac": "30:ae:a4:03:96:a8" } connected Packet NO.: 1, time used: 0.635692s Packet NO.: 2, time used: 0.643326s Packet NO.: 3, time used: 0.639247s Packet NO.: 4, time used: 0.637486s Packet NO.: 5, time used: 0.638007s Packet NO.: 6, time used: 0.639673s Packet NO.: 7, time used: 0.635873s Packet NO.: 8, time used: 0.639083s Packet NO.: 9, time used: 0.638372s Packet NO.: 10, time used: 0.635825s Packet NO.: 11, time used: 0.63933s Packet NO.: 12, time used: 0.640514s Packet NO.: 13, time used: 0.651622s Packet NO.: 14, time used: 0.635399s Packet NO.: 15, time used: 0.633999s Packet NO.: 16, time used: 0.642046s Packet NO.: 17, time used: 0.636034s Packet NO.: 18, time used: 0.634s Packet NO.: 19, time used: 0.641917s Packet NO.: 20, time used: 0.634763s Packet NO.: 21, time used: 0.637004s Packet NO.: 22, time used: 0.639767s Packet NO.: 23, time used: 0.640957s Packet NO.: 24, time used: 0.641996s Packet NO.: 25, time used: 0.641126s Packet NO.: 26, time used: 0.63957s Packet NO.: 27, time used: 0.641609s Packet NO.: 28, time used: 0.637018s Packet NO.: 29, time used: 0.6368s Packet NO.: 30, time used: 0.634749s Packet NO.: 31, time used: 0.633586s Packet NO.: 32, time used: 0.634311s Packet NO.: 33, time used: 0.63496s Packet NO.: 34, time used: 0.640297s Packet NO.: 35, time used: 0.64408s Packet NO.: 36, time used: 0.63855s Packet NO.: 37, time used: 0.632856s Packet NO.: 38, time used: 0.639827s Packet NO.: 39, time used: 0.641707s Packet NO.: 40, time used: 0.635856s Packet NO.: 41, time used: 0.638333s Packet NO.: 42, time used: 0.641669s Packet NO.: 43, time used: 0.634372s Packet NO.: 44, time used: 0.65415s Packet NO.: 45, time used: 0.639517s Packet NO.: 46, time used: 0.637973s Packet NO.: 47, time used: 0.644115s Packet NO.: 48, time used: 0.638485s Packet NO.: 49, time used: 0.642308s Packet NO.: 50, time used: 0.639105s Packet NO.: 51, time used: 0.636765s Packet NO.: 52, time used: 0.631903s Packet NO.: 53, time used: 0.681386s Packet NO.: 54, time used: 0.634737s Packet NO.: 55, time used: 0.641648s Packet NO.: 56, time used: 0.643582s Packet NO.: 57, time used: 0.636885s Packet NO.: 58, time used: 0.631757s Packet NO.: 59, time used: 0.642512s Packet NO.: 60, time used: 0.639893s Packet NO.: 61, time used: 0.638397s Packet NO.: 62, time used: 0.63751s Packet NO.: 63, time used: 0.641528s Packet NO.: 64, time used: 0.639858s Packet NO.: 65, time used: 0.642329s Packet NO.: 66, time used: 0.636603s Packet NO.: 67, time used: 0.634986s Packet NO.: 68, time used: 0.641883s Packet NO.: 69, time used: 0.637135s Packet NO.: 70, time used: 0.639046s Packet NO.: 71, time used: 0.641357s Packet NO.: 72, time used: 0.633942s Packet NO.: 73, time used: 0.634675s Packet NO.: 74, time used: 0.642398s Packet NO.: 75, time used: 0.650468s Packet NO.: 76, time used: 0.638624s Packet NO.: 77, time used: 0.643335s Packet NO.: 78, time used: 0.637059s Packet NO.: 79, time used: 0.635053s Packet NO.: 80, time used: 0.637182s Packet NO.: 81, time used: 0.638033s Packet NO.: 82, time used: 0.635974s Packet NO.: 83, time used: 0.638443s Packet NO.: 84, time used: 0.63591s Packet NO.: 85, time used: 0.639598s Packet NO.: 86, time used: 0.639959s Packet NO.: 87, time used: 0.637911s Packet NO.: 88, time used: 0.638151s Packet NO.: 89, time used: 0.636811s Packet NO.: 90, time used: 0.636061s Packet NO.: 91, time used: 0.636077s Packet NO.: 92, time used: 0.637843s Packet NO.: 93, time used: 0.641588s Packet NO.: 94, time used: 0.639297s Packet NO.: 95, time used: 0.642088s Packet NO.: 96, time used: 0.635662s Packet NO.: 97, time used: 0.638305s Packet NO.: 98, time used: 0.634205s Packet NO.: 99, time used: 0.644576s Packet NO.: 100, time used: 0.644314s Packet NO.: 101, time used: 0.639154s total time used: 64.56325700000s
with no btoa(), about 200ms is saved per 230 bytes packet.
@Aifer started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
test code with no btoa(), and interval = 0
result:
with no btoa(), about 200ms is saved per 230 bytes packet.