In this Gist I wanted to test how quickly Clojure performs 500 HTTP GET requests compared to GO. Surprisingly, using the http-kit Clojure library, a high-performance HTTP client/server implemented in Clojure(and some Java), in turned out that Clojure was faster at fetching http://clojure.org/ 500 times concurently.
I chose http-kit because it is a popular Clojure http client/server, and I did not want to test using purely existing Java based http client/server, like the http client in JDK 11+ which are more painful to use from Clojure due to their API being designed for Java usage.
In both the Clojure and GO solutions, I am doing asynchronous Get calls, to maximize the performance.
I've used Clojure's most common benchmark lib called criterium, which runs the form multiple times to make the JIT hot, and runs until it starts seeing conssistent results on timing to report the proper execution mean time.
I've used Go's testing lib, availaible in its standard library to run a Benchmark, where it too, will run multiple time until it starts getting confident timings. As per something I read online, Go can aggressively remove logic that it believes is unused, so based on advice online, I had results be stored in a package level var to avoid such optimiation and have Go simple not actually run getClojure.
I've used GO processes to concurently make the 500 requests in GO.
I am much more knowledgeable of Clojure, even though I did not try to optimize the Clojure version, I wrote the simplest implementation I knew. With GO, I am less knowledgeable, but similarly used the most straighforward way I knew how to implement the problem.
Clojure is the winner!
I was honestly surprised, I thought Go was going to be faster and was curious to see by how much, but Clojure turned out to be faster than GO.
- Clojure execution time : 745.907356 ms
- Go execution time : 1.269s
The benchmarks themselves run multiple times each, but I ran the benchmarks 10 times as well to see in case connection speed played a role, and everytime Clojure beat Go, and I was seeing similar-ish timings at +/- 200ms
mentirada