time-to-botec

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

commit f56b2ee6f4d0973a14a0386c4b678280940ee1c1
parent ce83739f232a64c39f43d2e2b72f3af6e03635b1
Author: NunoSempere <nuno.sempere@protonmail.com>
Date:   Sat, 24 Feb 2024 23:56:51 -0300

add experimental times

Diffstat:
MC/makefile | 11+++++++++++
MREADME.md | 1+
Mmakefile | 1+
Msquiggle.c/makefile | 14+++++++++++++-
Msquiggle.c/samples | 0
Msquiggle.c/samples.c | 27+++++++++++++++------------
Msquiggle.c/squiggle_c/squiggle.c | 4++--
7 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/C/makefile b/C/makefile @@ -25,6 +25,7 @@ DEBUG= #'-g' STANDARD=-std=c99 WARNINGS=-Wall OPTIMIZED=-O3 #-O3 actually gives better performance than -Ofast, at least for this version. Could also add -march=native +MORE_OPTIMIZATIONS=-Ofast -funit-at-a-time -march=native -fno-math-errno -ffast-math -std=gnu99 -fno-unroll-loops -flto LOCAL=-march=native OPENMP=-fopenmp @@ -32,10 +33,20 @@ OPENMP=-fopenmp STYLE_BLUEPRINT=webkit FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT) + ## make build build: $(SRC) $(CC) $(OPTIMIZED) $(DEBUG) $(SRC) $(LOCAL) $(OPENMP) $(MATH) -o $(OUTPUT) +build-experimental: + # https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html + rm -f *.gcda + $(CC) -fprofile-generate $(OPTIMIZATIONS) samples.c $(OPENMP) $(MATH) -o $(OUTPUT) + ./$(OUTPUT) + $(CC) -fprofile-use $(OPTIMIZATIONS) 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> + static: $(CC) $(OPTIMIZED) $(DEBUG) $(SRC) $(LOCAL) $(OPENMP) $(MATH) -o $(OUTPUT) diff --git a/README.md b/README.md @@ -24,6 +24,7 @@ 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 | diff --git a/makefile b/makefile @@ -20,6 +20,7 @@ time-all: @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 (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 diff --git a/squiggle.c/makefile b/squiggle.c/makefile @@ -5,7 +5,7 @@ OPTIMIZATIONS=-funit-at-a-time -march=native -fno-math-errno -ffast-math -std=gn build: $(CC) -O3 samples.c ./squiggle_c/squiggle.c ./squiggle_c/squiggle_more.c -lm -fopenmp -o $(OUTPUT) -experimental: +build-experimental: # https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html rm -f *.gcda $(CC) -Ofast -fprofile-generate $(OPTIMIZATIONS) samples.c ./squiggle_c/squiggle.c ./squiggle_c/squiggle_more.c -lm -fopenmp -o $(OUTPUT) @@ -26,6 +26,18 @@ install: wget https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/examples/more/12_time_to_botec_parallel/example.c -O samples.c sed -i 's|../../..|squiggle_c|' samples.c +install-custom: + rm -r squiggle_c + wget https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle.c + wget https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle.h + wget https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle_more.c + wget https://git.nunosempere.com/personal/squiggle.c/raw/branch/master/squiggle_more.h + 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 + sed -i 's|../../..|squiggle_c|' samples.c + install-git: rm -r squiggle_c git clone https://git.nunosempere.com/personal/squiggle.c 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 @@ -3,21 +3,24 @@ #include <stdio.h> #include <stdlib.h> +double cumsum_p0 = 0.6; +double cumsum_p1 = 0.8; +double cumsum_p2 = 0.9; +double cumsum_p3 = 1.0; + double sampler_result(uint64_t * seed) { - double p_a = 0.8; - double p_b = 0.5; - double p_c = p_a * p_b; - - double sample_0(uint64_t * seed) { UNUSED(seed); return 0; } - double sample_1(uint64_t * seed) { UNUSED(seed); return 1; } - double sample_few(uint64_t * seed) { return sample_to(1, 3, seed); } - double sample_many(uint64_t * seed) { return sample_to(2, 10, seed); } - int n_dists = 4; - double weights[] = { 1 - p_c, p_c / 2, p_c / 4, p_c / 4 }; - double (*samplers[])(uint64_t*) = { sample_0, sample_1, sample_few, sample_many }; - return sample_mixture(samplers, weights, n_dists, seed); + double p = sample_unit_uniform(seed); + if(p< cumsum_p0){ + return 0; + } else if (p < cumsum_p1){ + return 1; + } else if (p < cumsum_p2){ + return sample_to(1,3, seed); + } else { + return sample_to(2, 10, seed); + } } int main() diff --git a/squiggle.c/squiggle_c/squiggle.c b/squiggle.c/squiggle_c/squiggle.c @@ -50,7 +50,7 @@ double sample_unit_normal(uint64_t* seed) // // See: <https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform> double u1 = sample_unit_uniform(seed); double u2 = sample_unit_uniform(seed); - double z = sqrt(-2.0 * log(u1)) * sin(2 * PI * u2); + double z = sqrt(-2.0 * log(u1)) * sin(2.0 * PI * u2); return z; } @@ -90,7 +90,7 @@ double sample_normal_from_90_ci(double low, double high, uint64_t* seed) // 5. If we want a 90% confidence interval from high to low, // we can set mean = (high + low)/2; the midpoint, and L = high-low, // Normal([high + low]/2, [high - low]/(2 * 1.6448536269514722)) - double mean = (high + low) / 2.0; + double mean = (high + low) * 0.5; double std = (high - low) / (2.0 * NORMAL90CONFIDENCE); return sample_normal(mean, std, seed); }