time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

commit f07ebd80cef0cca41b6f5bca56cd6ad1f2d7f5e9
parent f56b2ee6f4d0973a14a0386c4b678280940ee1c1
Author: NunoSempere <nuno.sempere@protonmail.com>
Date:   Sun, 25 Feb 2024 00:28:41 -0300

add more comparison points

Diffstat:
MC/makefile | 4++--
MREADME.md | 28++++++++++++++--------------
Mmakefile | 6+++---
Msquiggle.c/samples | 0
Msquiggle.c/samples.c | 2+-
Mtime.txt | 314++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
6 files changed, 291 insertions(+), 63 deletions(-)

diff --git a/C/makefile b/C/makefile @@ -41,9 +41,9 @@ build: $(SRC) build-experimental: # https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html rm -f *.gcda - $(CC) -fprofile-generate $(OPTIMIZATIONS) samples.c $(OPENMP) $(MATH) -o $(OUTPUT) + $(CC) -fprofile-generate $(OPTIMIZATIONS) $(LOCAL) samples.c $(OPENMP) $(MATH) -o $(OUTPUT) ./$(OUTPUT) - $(CC) -fprofile-use $(OPTIMIZATIONS) samples.c $(OPENMP) $(MATH) -o $(OUTPUT) + $(CC) -fprofile-use $(OPTIMIZATIONS) $(LOCAL) samples.c $(OPENMP) $(MATH) -o $(OUTPUT) rm *.gcda # Using -Ofast increases speed a bit, but I don't trust it. <https://stackoverflow.com/questions/61232427/gcc-differences-between-o3-vs-ofast-optimizations> diff --git a/README.md b/README.md @@ -24,20 +24,20 @@ The name of this repository is a pun on two meanings of "time to": "how much tim | Language | Time | Lines of code | |-----------------------------|-----------|---------------| -| squiggle.c (danger mode) | 7.20ms | 29* | -| C | 6.20ms | 252 | -| squiggle.c | 7.20ms | 29* | -| go | 32.70ms | 150 | -| Nim | 41.10ms | 84 | -| Lua (LuaJIT) | 68.80ms | 82 | -| Python (well-tuned numpy) | 118ms | 123 | -| OCaml (flambda) | 185ms | 123 | -| Squiggle (bun) | 384ms | 14* | -| Javascript (node) | 0.423s | 69 | -| SquigglePy (v0.27) | 1.542s | 18* | -| R (3.6.1) | 4.494s | 49 | -| Python 3.9 | 11.909s | 56 | -| Gavin Howard's bc | 16.170s | 101 | +| squiggle.c (danger) | 4.22ms | 35* | +| C | 6.20ms | 252 | +| squiggle.c | 7.20ms | 29* | +| go | 21.20ms | 150 | +| Nim | 41.10ms | 84 | +| Lua (LuaJIT) | 68.80ms | 82 | +| Python (numpy) | 118ms | 48 | +| OCaml (flambda) | 185ms | 123 | +| Squiggle (bun) | 384ms | 14* | +| Javascript (node) | 395ms | 69 | +| SquigglePy (v0.27) | 1,542ms | 18* | +| R (3.6.1) | 4,494ms | 49 | +| Python 3.9 | 11,909ms | 56 | +| Gavin Howard's bc | 16,170ms | 101 | Time measurements taken with the [time](https://man7.org/linux/man-pages/man1/time.1.html) tool, using 1M samples. But different implementations use different algorithms and, occasionally, different time measuring methodologies (for the C, Nim and Lua implementations, I run the program 100 times and take the mean). Their speed was also measured under different loads in my machine. So I think that these time estimates are accurate within maybe ~2x or so. diff --git a/makefile b/makefile @@ -16,14 +16,14 @@ time-all: @echo "# nim" && cd nim && make time-linux && echo && echo @echo "# ocaml" && cd ocaml && make time-linux && echo && echo @echo "# Python (3.9)" && cd python && time python3.9 samples.py && echo && echo + @echo "# Python (numpy)" && cd python && time python3.9 samples-fast.py && echo && echo @echo "# R (3.6.1)" && cd R && time r samples.R && echo && echo @echo "# Squiggle (0.8.6)" && cd squiggle && make time-linux && echo && echo @echo "# SquigglePy (0.27)" && cd squigglepy && make time && echo && echo - @echo "# squiggle.c" && cd squiggle.c && make time-linux && echo && echo + @echo "# squiggle.c" && cd squiggle.c && make install && make build && make time-linux && echo && echo + @echo "# squiggle.c" && cd squiggle.c && make install-custom && make build-experimental && make time-linux && echo && echo @echo "# squiggle.c (danger mode)" && cd squiggle.c && make install-custom && make build-experimental && make time-linux && echo && echo @echo "# squiggle.go" && cd go && make time-linux && echo && echo - - record: make time-all > time.txt 2>&1 diff --git a/squiggle.c/samples b/squiggle.c/samples Binary files differ. diff --git a/squiggle.c/samples.c b/squiggle.c/samples.c @@ -11,7 +11,7 @@ double cumsum_p3 = 1.0; double sampler_result(uint64_t * seed) { - double p = sample_unit_uniform(seed); + double p = sample_uniform(0, 1, seed); if(p< cumsum_p0){ return 0; } else if (p < cumsum_p1){ diff --git a/time.txt b/time.txt @@ -1,54 +1,54 @@ # bc time ghbc -l squiggle.bc estimate.bc -.8872657001481914 +.8880956915396169 -real 0m16.170s -user 0m16.115s -sys 0m0.008s +real 0m15.941s +user 0m15.936s +sys 0m0.000s # C Running 100x and taking avg time: OMP_NUM_THREADS=16 out/samples -Time using 16 threads: 6.20ms +Time using 16 threads: 6.10ms # js (bun) -0.8861715640546732 +0.8890972216037947 -real 0m0.562s -user 0m0.540s -sys 0m0.074s +real 0m0.592s +user 0m0.560s +sys 0m0.047s # js (node) -0.8863245179136781 +0.8886602152847817 -real 0m0.423s -user 0m0.509s -sys 0m0.077s +real 0m0.404s +user 0m0.518s +sys 0m0.081s # lua (luajit) Requires /bin/time, found on GNU/Linux systems Running 100x and taking avg time of: luajit samples.lua -Time: 68.80ms +Time: 67.90ms # nim Requires /bin/time, found on GNU/Linux systems -Running 100x and taking avg time of: -Time: 41.10ms +Running 100x and taking avg time of: +Time: 41.00ms # ocaml Requires /bin/time, found on GNU/Linux systems -Running 100x and taking avg time of: +Running 100x and taking avg time of: Time: 185.50ms @@ -56,53 +56,281 @@ Time: 185.50ms # Python (3.9) 0.8887373869178242 -real 0m11.909s -user 0m12.149s -sys 0m1.145s +real 0m12.096s +user 0m12.307s +sys 0m1.081s + + +# Python (numpy) +0.8887373869178242 + +real 0m11.907s +user 0m12.180s +sys 0m1.092s # R (3.6.1) -[1] 0.8862725 +[1] 0.8875992 -real 0m4.494s -user 0m4.465s -sys 0m0.025s +real 0m4.567s +user 0m4.532s +sys 0m0.029s # Squiggle (0.8.6) Requires /bin/time, found on GNU/Linux systems -Running 100x and taking avg time of: -Time: 384.00ms +Running 100x and taking avg time of: +Time: 379.80ms # SquigglePy (0.27) time python3.9 samples.py -100%|█████████████████████████████████████████████████████████████████████████████████████| 4/4 [00:00<00:00, 22.58it/s] -100%|████████████████████████████████████████████████████████████████████| 1000000/1000000 [00:00<00:00, 1322894.77it/s] -0.8876134007583529 + 0%| | 0/4 [00:00<?, ?it/s] 75%|███████▌ | 3/4 [00:00<00:00, 25.71it/s]100%|██████████| 4/4 [00:00<00:00, 21.89it/s] + 0%| | 0/1000000 [00:00<?, ?it/s] 10%|█ | 100926/1000000 [00:00<00:00, 1009253.74it/s] 23%|██▎ | 233593/1000000 [00:00<00:00, 1195967.71it/s] 37%|███▋ | 369110/1000000 [00:00<00:00, 1268660.47it/s] 51%|█████ | 506546/1000000 [00:00<00:00, 1310386.16it/s] 65%|██████▍ | 647417/1000000 [00:00<00:00, 1345838.18it/s] 79%|███████▉ | 787714/1000000 [00:00<00:00, 1365262.30it/s] 93%|█████████▎| 929866/1000000 [00:00<00:00, 1383650.33it/s]100%|██████████| 1000000/1000000 [00:00<00:00, 1321333.61it/s] +0.8885170299156587 -real 0m1.542s -user 0m1.989s -sys 0m2.226s +real 0m1.534s +user 0m1.951s +sys 0m2.252s # squiggle.c -Running 100x and taking avg time: OMP_NUM_THREADS=16 ./samples -Time using 16 threads: 7.20ms +rm -r squiggle_c +wget https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle.c +--2024-02-25 00:21:11-- https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle.c +Resolving git.nunosempere.com (git.nunosempere.com)... 164.92.249.28 +Connecting to git.nunosempere.com (git.nunosempere.com)|164.92.249.28|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 7942 (7.8K) [text/plain] +Saving to: ‘squiggle.c’ + + 0K ....... 100% 1.24G=0s + +2024-02-25 00:21:13 (1.24 GB/s) - ‘squiggle.c’ saved [7942/7942] + +wget https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle.h +--2024-02-25 00:21:13-- https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle.h +Resolving git.nunosempere.com (git.nunosempere.com)... 164.92.249.28 +Connecting to git.nunosempere.com (git.nunosempere.com)|164.92.249.28|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 1348 (1.3K) [text/plain] +Saving to: ‘squiggle.h’ + + 0K . 100% 284M=0s + +2024-02-25 00:21:15 (284 MB/s) - ‘squiggle.h’ saved [1348/1348] + +wget https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle_more.c +--2024-02-25 00:21:15-- https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle_more.c +Resolving git.nunosempere.com (git.nunosempere.com)... 164.92.249.28 +Connecting to git.nunosempere.com (git.nunosempere.com)|164.92.249.28|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 15606 (15K) [text/plain] +Saving to: ‘squiggle_more.c’ + + 0K .......... ..... 100% 99.8M=0s + +2024-02-25 00:21:17 (99.8 MB/s) - ‘squiggle_more.c’ saved [15606/15606] -# go +wget https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle_more.h +--2024-02-25 00:21:17-- https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle_more.h +Resolving git.nunosempere.com (git.nunosempere.com)... 164.92.249.28 +Connecting to git.nunosempere.com (git.nunosempere.com)|164.92.249.28|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 1111 (1.1K) [text/plain] +Saving to: ‘squiggle_more.h’ -make time-linux + 0K . 100% 244M=0s + +2024-02-25 00:21:18 (244 MB/s) - ‘squiggle_more.h’ saved [1111/1111] + +mkdir temp +mv squiggle* temp +mv temp squiggle_c +wget https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/examples/more/12_time_to_botec_parallel/example.c -O samples.c +--2024-02-25 00:21:18-- https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/examples/more/12_time_to_botec_parallel/example.c +Resolving git.nunosempere.com (git.nunosempere.com)... 164.92.249.28 +Connecting to git.nunosempere.com (git.nunosempere.com)|164.92.249.28|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 1022 [text/plain] +Saving to: ‘samples.c’ + + 0K 100% 248M=0s + +2024-02-25 00:21:20 (248 MB/s) - ‘samples.c’ saved [1022/1022] + +sed -i 's|../../..|squiggle_c|' samples.c +gcc -O3 samples.c ./squiggle_c/squiggle.c ./squiggle_c/squiggle_more.c -lm -fopenmp -o ./samples +Running 1000x and taking avg time: OMP_NUM_THREADS=16 ./samples +Time using 16 threads: 8.69ms + + + +# squiggle.c +rm -r squiggle_c +wget https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle.c +--2024-02-25 00:21:29-- https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle.c +Resolving git.nunosempere.com (git.nunosempere.com)... 164.92.249.28 +Connecting to git.nunosempere.com (git.nunosempere.com)|164.92.249.28|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 7942 (7.8K) [text/plain] +Saving to: ‘squiggle.c’ + + 0K ....... 100% 1.98G=0s + +2024-02-25 00:21:32 (1.98 GB/s) - ‘squiggle.c’ saved [7942/7942] + +wget https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle.h +--2024-02-25 00:21:32-- https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle.h +Resolving git.nunosempere.com (git.nunosempere.com)... 164.92.249.28 +Connecting to git.nunosempere.com (git.nunosempere.com)|164.92.249.28|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 1348 (1.3K) [text/plain] +Saving to: ‘squiggle.h’ + + 0K . 100% 277M=0s + +2024-02-25 00:21:33 (277 MB/s) - ‘squiggle.h’ saved [1348/1348] + +wget https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle_more.c +--2024-02-25 00:21:33-- https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle_more.c +Resolving git.nunosempere.com (git.nunosempere.com)... 164.92.249.28 +Connecting to git.nunosempere.com (git.nunosempere.com)|164.92.249.28|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 15606 (15K) [text/plain] +Saving to: ‘squiggle_more.c’ + + 0K .......... ..... 100% 102M=0s + +2024-02-25 00:21:35 (102 MB/s) - ‘squiggle_more.c’ saved [15606/15606] + +wget https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle_more.h +--2024-02-25 00:21:35-- https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle_more.h +Resolving git.nunosempere.com (git.nunosempere.com)... 164.92.249.28 +Connecting to git.nunosempere.com (git.nunosempere.com)|164.92.249.28|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 1111 (1.1K) [text/plain] +Saving to: ‘squiggle_more.h’ + + 0K . 100% 490M=0s + +2024-02-25 00:21:36 (490 MB/s) - ‘squiggle_more.h’ saved [1111/1111] + +mkdir temp +mv squiggle* temp +mv temp squiggle_c +wget https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/examples/more/15_time_to_botec_custom_mixture/example.c -O samples.c +--2024-02-25 00:21:36-- https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/examples/more/15_time_to_botec_custom_mixture/example.c +Resolving git.nunosempere.com (git.nunosempere.com)... 164.92.249.28 +Connecting to git.nunosempere.com (git.nunosempere.com)|164.92.249.28|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 795 [text/plain] +Saving to: ‘samples.c’ + + 0K 100% 256M=0s + +2024-02-25 00:21:38 (256 MB/s) - ‘samples.c’ saved [795/795] + +sed -i 's|../../..|squiggle_c|' samples.c +# https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html +rm -f *.gcda +gcc -Ofast -fprofile-generate -funit-at-a-time -march=native -fno-math-errno -ffast-math -std=gnu99 -fno-unroll-loops -flto samples.c ./squiggle_c/squiggle.c ./squiggle_c/squiggle_more.c -lm -fopenmp -o ./samples +././samples +Avg: 0.888998 +gcc -Ofast -fprofile-use -funit-at-a-time -march=native -fno-math-errno -ffast-math -std=gnu99 -fno-unroll-loops -flto samples.c ./squiggle_c/squiggle.c ./squiggle_c/squiggle_more.c -lm -fopenmp -o ./samples +rm *.gcda +# Using -Ofast increases speed a bit, but I don't trust it. <https://stackoverflow.com/questions/61232427/gcc-differences-between-o3-vs-ofast-optimizations> +Running 1000x and taking avg time: OMP_NUM_THREADS=16 ./samples +Time using 16 threads: 4.95ms + + + +# squiggle.c (danger mode) +rm -r squiggle_c +wget https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle.c +--2024-02-25 00:21:44-- https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle.c +Resolving git.nunosempere.com (git.nunosempere.com)... 164.92.249.28 +Connecting to git.nunosempere.com (git.nunosempere.com)|164.92.249.28|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 7942 (7.8K) [text/plain] +Saving to: ‘squiggle.c’ + + 0K ....... 100% 1.26G=0s + +2024-02-25 00:21:46 (1.26 GB/s) - ‘squiggle.c’ saved [7942/7942] + +wget https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle.h +--2024-02-25 00:21:46-- https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle.h +Resolving git.nunosempere.com (git.nunosempere.com)... 164.92.249.28 +Connecting to git.nunosempere.com (git.nunosempere.com)|164.92.249.28|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 1348 (1.3K) [text/plain] +Saving to: ‘squiggle.h’ + + 0K . 100% 225M=0s + +2024-02-25 00:21:47 (225 MB/s) - ‘squiggle.h’ saved [1348/1348] + +wget https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle_more.c +--2024-02-25 00:21:47-- https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle_more.c +Resolving git.nunosempere.com (git.nunosempere.com)... 164.92.249.28 +Connecting to git.nunosempere.com (git.nunosempere.com)|164.92.249.28|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 15606 (15K) [text/plain] +Saving to: ‘squiggle_more.c’ + + 0K .......... ..... 100% 103M=0s + +2024-02-25 00:21:49 (103 MB/s) - ‘squiggle_more.c’ saved [15606/15606] + +wget https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle_more.h +--2024-02-25 00:21:49-- https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle_more.h +Resolving git.nunosempere.com (git.nunosempere.com)... 164.92.249.28 +Connecting to git.nunosempere.com (git.nunosempere.com)|164.92.249.28|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 1111 (1.1K) [text/plain] +Saving to: ‘squiggle_more.h’ + + 0K . 100% 219M=0s + +2024-02-25 00:21:56 (219 MB/s) - ‘squiggle_more.h’ saved [1111/1111] + +mkdir temp +mv squiggle* temp +mv temp squiggle_c +wget https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/examples/more/15_time_to_botec_custom_mixture/example.c -O samples.c +--2024-02-25 00:21:56-- https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/examples/more/15_time_to_botec_custom_mixture/example.c +Resolving git.nunosempere.com (git.nunosempere.com)... 164.92.249.28 +Connecting to git.nunosempere.com (git.nunosempere.com)|164.92.249.28|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 795 [text/plain] +Saving to: ‘samples.c’ + + 0K 100% 184M=0s + +2024-02-25 00:21:59 (184 MB/s) - ‘samples.c’ saved [795/795] + +sed -i 's|../../..|squiggle_c|' samples.c +# https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html +rm -f *.gcda +gcc -Ofast -fprofile-generate -funit-at-a-time -march=native -fno-math-errno -ffast-math -std=gnu99 -fno-unroll-loops -flto samples.c ./squiggle_c/squiggle.c ./squiggle_c/squiggle_more.c -lm -fopenmp -o ./samples +././samples +Avg: 0.888998 +gcc -Ofast -fprofile-use -funit-at-a-time -march=native -fno-math-errno -ffast-math -std=gnu99 -fno-unroll-loops -flto samples.c ./squiggle_c/squiggle.c ./squiggle_c/squiggle_more.c -lm -fopenmp -o ./samples +rm *.gcda +# Using -Ofast increases speed a bit, but I don't trust it. <https://stackoverflow.com/questions/61232427/gcc-differences-between-o3-vs-ofast-optimizations> +Running 1000x and taking avg time: OMP_NUM_THREADS=16 ./samples +Time using 16 threads: 4.44ms + + + +# squiggle.go Running 100x and taking avg time: ./squiggle -Time using 16 threads: 32.70ms +Time using 16 threads: 21.30ms -# Python (serialized numpy) -time python3 samples-fast.py +# Python (numpy) +Mean result: 0.8848672124030412 Mean result: 0.8848672124030412 - -real 0m0.117s -user 0m0.146s -sys 0m0.298s