Sample factorial calculating task. Three versions.
v1 : calculate two factorials simultaniously in two goroutines.
v2 : calculate N factorials in one loop.
v3 : calculate N factorials in one loop with parallelism.
Results on [200000,300000]
:
v1 : 10.90 seconds
v2 : 9.47 seconds
v3 : 1.38 seconds
Add "count": 1
parameter to get the number of bits in the result, not the actual numbers (see examples below).
Compiled and checked with go 1.17.
Run make all
to build all three versions in ./build/.
Run make help
to get more info.
Sample commands:
time curl --request POST --url http://localhost:8989/factorial --data '{"numbers": [200000, 300000]}' -o /dev/null
time curl --request POST --url http://localhost:8989/factorial --data '{"numbers": [200000, 300000], "count": 1}'