add squiggle.c

This commit is contained in:
NunoSempere 2023-08-17 14:36:03 +02:00
parent 3e0282ab17
commit 64e337a743
2 changed files with 16 additions and 1 deletions

View File

@ -25,6 +25,7 @@ The title of this repository is a pun on two meanings of "time to": "how much ti
| Language | Time | Lines of code |
|-----------------------------|-----------|---------------|
| C (optimized, 16 threads) | 5ms | 249 |
| squiggle.c | 37ms | 54 |
| Nim | 38ms | 84 |
| Lua (LuaJIT) | 68ms | 82 |
| Lua | 278ms | 82 |
@ -37,7 +38,7 @@ The title of this repository is a pun on two meanings of "time to": "how much ti
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.
Note that the number of lines is much shorter for Squiggle and SquigglePy because I'm just counting the lines needed to get Squiggle and SquigglePy to output a model, not the lines inside them.
Note that the number of lines is much shorter for Squiggle, SquigglePy and squiggle.c because I'm just counting the lines needed to get these libraries to output a model, not the lines inside them.
## Notes
@ -74,6 +75,10 @@ Once the code was at 6.6ms, there was a 0.6ms gain possible by using OMP better,
Although the above paragraphs were written in the first person, the C code was written together with Jorge Sierra, who translated the algorithmic improvements from nim to it and added the initial multithreading support.
### squiggle.c
squiggle.c is a minimalistic version of squiggle focused on understandability and being self-contained. You can see the code [here](https://git.nunosempere.com/personal/squiggle.c), and the code for the specific example [here](https://git.nunosempere.com/personal/squiggle.c/src/branch/master/examples/02_many_samples_time_to_botec).
### NodeJS and Squiggle
Using [bun](https://bun.sh/) instead of node is actually a bit slower. Also, both the NodeJS and the Squiggle code use [stdlib](https://stdlib.io/) in their innards, which has a bunch of interleaved functions that make the code slower. It's possible that not using that external library could make the code faster, but at the same time, the js approach does seem to be to use external libraries whenever possible.

View File

@ -128,3 +128,13 @@ Requires /bin/time, found on GNU/Linux systems
Running 100x and taking avg time of: luajit samples.lua
Time: 68.60ms
## squiggle.c
— make time-linux
Requires /bin/time, found on GNU/Linux systems
Running 100x and taking avg time example
Time using 1 thread: 37.60ms