Self-hosted Speed Test for HTML5 and more. Easy setup, examples, configurable, mobile friendly. Supports PHP, Node, Multiple servers, and more - librespeed/speedtest
Also the ISP probably knows most of the servers speedtest owns and accelerate speeds for them along with other popular speed test websites, while throttling other regular connections.
As somebody who once worked at an ISP: they absolutely do that, and it isn't illegal. In fact, ISP's host many of Ookla's speedtest servers. The less infrastructure your test needs to go through, the better the results will be—there's nothing faster than a network that's communicating with itself.