speedtest icon indicating copy to clipboard operation
speedtest copied to clipboard

CLI

Open notpushkin opened this issue 2 years ago • 8 comments

Thanks for this project! Are you also planning to add a CLI interface? Someone on HN has already started an implementation, but perhaps you could collab and release it as part of this package.

notpushkin avatar Aug 10 '23 17:08 notpushkin

Oh hi, I am that someone :) It's more for a personal project of mine, but I'd be happy to contribute back if there is interest. Unfortunately, according to #17 a CLI is out of reach (for now) due to nodejs being incompatible with this library.

bmo-at avatar Aug 11 '23 08:08 bmo-at

https://github.com/nodejs/undici/pull/2481 was just merged, which adds the PerformanceTiming API entries needed for this library. So we're getting closer to getting this working in node.

ToshB avatar Dec 20 '23 09:12 ToshB

That's great @ToshB! Any idea of how long it will take of the release of Node with the mentioned features?

hakonk avatar Jan 09 '24 18:01 hakonk

Looks like it was merged into Node two days ago, https://github.com/nodejs/node/commit/05f81721889571f615e36bf70fac759f4d118513, so it shouldn't be too long.

ToshB avatar Jan 09 '24 19:01 ToshB

And works like a charm too with the nightly build of node 22:

❯ node
Welcome to Node.js v22.0.0-nightly202401090090c10782.
Type ".help" for more information.
> const {default: Speedtest } = await import('@cloudflare/speedtest');
undefined
> (node:50124) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
> new Speedtest().onFinish = results => console.log(results.getSummary());
[Function (anonymous)]
> {
  download: 225662382.7740472,
  upload: 37244214.56244167,
  latency: 17.63653700000069,
  jitter: 1.0500115789465496,
  downLoadedLatency: 27.033390500009148,
  downLoadedJitter: 16.086571000001342,
  upLoadedLatency: 42.60906900000435,
  upLoadedJitter: 70.95178205555446
}

I was gonna try and run this in my golang based speedtest background task as some sort of abomination where I'd use it in chrome via devtools and get the results that way, but I was too busy lately and my current speedtest provider was ok enough. But now I will definitely rebuild this with the cloudflare speedtest. Thanks @ToshB for your effort!

bmo-at avatar Jan 09 '24 21:01 bmo-at

I tried it too with v22 nightly. Very smooth! Thanks @ToshB!

hakonk avatar Jan 11 '24 08:01 hakonk

Very cool! I am curious to see if the Node speedtest results are comparable to the browser results. I would assume the fetch-implementations in browsers are tuned to the extreme..

Note that there are some speedtest engines which is still not compatible with Node. Specifically the packetloss tests, which requires WebRTC. I was not able to find a working Node implementation of RTCPeerConnection.

ToshB avatar Jan 11 '24 08:01 ToshB

Very cool! I am curious to see if the Node speedtest results are comparable to the browser results. I would assume the fetch-implementations in browsers are tuned to the extreme..

I've tried a browser based speed test in chromium on a raspberrypi where the bandwidth was severely limited for reasons I don't know. The ookla speed test CLI works, but I'm a bit cautious as it collects so much data from the client.

This node based speed test seems to be a better alternative.

hakonk avatar Jan 11 '24 13:01 hakonk