move nim to top level, add to README
This commit is contained in:
parent
a84b6b9cc0
commit
2cf684da56
30
README.md
30
README.md
|
@ -13,29 +13,35 @@ The title of this repository is a pun on two meanings of "time to": "how much ti
|
||||||
- [x] Squiggle
|
- [x] Squiggle
|
||||||
- [x] Javascript (NodeJS)
|
- [x] Javascript (NodeJS)
|
||||||
- [x] C
|
- [x] C
|
||||||
|
- [x] Nim
|
||||||
|
|
||||||
## Performance table
|
## Performance table
|
||||||
|
|
||||||
With the [time](https://man7.org/linux/man-pages/man1/time.1.html) tool, using 1M samples:
|
With the [time](https://man7.org/linux/man-pages/man1/time.1.html) tool, using 1M samples:
|
||||||
|
|
||||||
| Language | Time |
|
| Language | Time |
|
||||||
|----------|-----------|
|
|----------------------|-----------|
|
||||||
| C | 0m0,442s |
|
| Nim | 0m0.183s |
|
||||||
| Node | 0m0,732s |
|
| C | 0m0,442s |
|
||||||
| Squiggle | 0m1,536s |
|
| Node | 0m0,732s |
|
||||||
| R | 0m7,000s |
|
| Squiggle | 0m1,536s |
|
||||||
| Python (CPython) | 0m16,641s |
|
| R | 0m7,000s |
|
||||||
|
| Python (CPython) | 0m16,641s |
|
||||||
|
|
||||||
|
I was very surprised that Node/Squiggle code was almost as fast as the raw C code. For the Python code, it's possible that the lack of speed is more a function of me not being as familiar with Python. It's also very possible that the code would run faster with [PyPy](https://doc.pypy.org).
|
||||||
|
|
||||||
I was very surprised that Node/Squiggle code was almost as fast as the raw C code. For the Python code, it's possible that the lack of speed is more a function of me not being as familiar with Python. It's also very possible that the code would run faster with [PyPy](https://doc.pypy.org)
|
I was also really happy with trying [Nim](https://nim-lang.org/). The version which beats all others is just the normal usage of Nim, in the "release" compilation mode (the "danger" compilation mode shaves of a few more miliseconds). The Nim version has the particularity that I define the normal function from scratch, using the [Box–Muller transform](https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform#Basic_form). For Nim I also have a version of the code which takes around 4 seconds, where I define some very inefficient sine & logarithm functions to feed into the Box-Muller method, because it felt like fun to really write a botec tool really from scratch.
|
||||||
|
|
||||||
## Languages I may add later
|
## Languages I may add later
|
||||||
|
|
||||||
- Julia (TuringML)
|
- [ ] Julia (TuringML)
|
||||||
- Rust
|
- [ ] Rust
|
||||||
- Lisp
|
- [ ] Lisp
|
||||||
|
- [ ] Stan
|
||||||
|
- [ ] Go
|
||||||
|
- [ ] Zig
|
||||||
|
- [ ] Forth
|
||||||
- ... and suggestions welcome
|
- ... and suggestions welcome
|
||||||
- Stan
|
|
||||||
|
|
||||||
## Roadmap
|
## Roadmap
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -29,7 +29,7 @@ proc sine(x: float): float =
|
||||||
|
|
||||||
## Arithmetic-geomtric mean
|
## Arithmetic-geomtric mean
|
||||||
proc ag(x: float, y: float): float =
|
proc ag(x: float, y: float): float =
|
||||||
let n = 16 # just some high number
|
let n = 32 # just some high number
|
||||||
var a = (x + y)/2.0
|
var a = (x + y)/2.0
|
||||||
var b = sqrt(x * y)
|
var b = sqrt(x * y)
|
||||||
for i in 0..n:
|
for i in 0..n:
|
||||||
|
@ -41,7 +41,7 @@ proc ag(x: float, y: float): float =
|
||||||
## Find m such that x * 2^m > 2^precision/2
|
## Find m such that x * 2^m > 2^precision/2
|
||||||
proc find_m(x:float): float =
|
proc find_m(x:float): float =
|
||||||
var m = 0.0;
|
var m = 0.0;
|
||||||
let precision = 32 # bits
|
let precision = 64 # bits
|
||||||
let c = pow(2.0, precision.float / 2.0)
|
let c = pow(2.0, precision.float / 2.0)
|
||||||
while x * pow(2.0, m) < c:
|
while x * pow(2.0, m) < c:
|
||||||
m = m + 1
|
m = m + 1
|
|
@ -8,4 +8,5 @@ run: samples
|
||||||
./samples $(VERBOSE)
|
./samples $(VERBOSE)
|
||||||
|
|
||||||
examine: samples
|
examine: samples
|
||||||
nim c $(VERBOSE) -d:release samples.nim && time ./samples $(VERBOSE)
|
nim c $(VERBOSE) -d:release samples.nim && time ./samples $(VERBOSE) && echo
|
||||||
|
nim c $(VERBOSE) -d:danger samples.nim && time ./samples $(VERBOSE)
|
BIN
nim/samples
Executable file
BIN
nim/samples
Executable file
Binary file not shown.
15
time.txt
15
time.txt
|
@ -36,3 +36,18 @@ real 0m7,000s
|
||||||
user 0m6,944s
|
user 0m6,944s
|
||||||
sys 0m0,052s
|
sys 0m0,052s
|
||||||
|
|
||||||
|
## Nim
|
||||||
|
|
||||||
|
nim c --verbosity:0 -d:release samples.nim && time ./samples --verbosity:0 && echo
|
||||||
|
0.8873815480558296
|
||||||
|
|
||||||
|
real 0m0.183s
|
||||||
|
user 0m0.150s
|
||||||
|
sys 0m0.032s
|
||||||
|
|
||||||
|
nim c --verbosity:0 -d:danger samples.nim && time ./samples --verbosity:0
|
||||||
|
0.8886260086130379
|
||||||
|
|
||||||
|
real 0m0.157s
|
||||||
|
user 0m0.136s
|
||||||
|
sys 0m0.020s
|
||||||
|
|
BIN
wip/nim/samples
BIN
wip/nim/samples
Binary file not shown.
Loading…
Reference in New Issue
Block a user