Files in directory chrestomathy/kal in any check-in
- go
- nelua-1
- nelua-2
- nim
- rust
- v
- diet
- README.md
kal - calorie-counting unix filter
The idea is to have a file with your daily information in this format, with an editor that has a hotkey bound to run the file through this program. In this way you get, in vim, or any editor, the feeling of an Emacs mode dedicated to calorie tracking. You can start the day by typing
d now
t 0 / 2000 (0) = 0%
b 1000 = 0% (0)
k 0% 170 3 16 20 chobani "some yogurt drink"
And then have kal fill in the details and update them as you add new meals or burn more calories throughout the day:
d Saturday, 18 Nov 2023
t 170 / 2000 (1830) = 8%
b 1000 = 588% (-830)
T 3:16:20 = 39 51%
k 8% 170 3 16 20 chobani "some yogurt drink"
The versions
These were organically written as I tried different programs. Go has the most mark on the format as fmt.Sscanf() needed double-quoted strings. nelua-1 is the very first program I wrote in Nelua, nelua-2 is more recently written and reflects a greater understanding of the language (using Lua-style string matching, .neluacfg.lua instead of Makefile, etc.)
Benchmark
Benchmark 1: ./go/kal
Time (mean ± σ): 2.8 ms ± 0.5 ms [User: 1.3 ms, System: 1.5 ms]
Range (min … max): 1.6 ms … 4.8 ms 1640 runs
Benchmark 2: ./nelua-1/kal
Time (mean ± σ): 1.7 ms ± 0.3 ms [User: 1.1 ms, System: 0.4 ms]
Range (min … max): 1.0 ms … 2.5 ms 1690 runs
Benchmark 3: ./nelua-2/kal
Time (mean ± σ): 1.4 ms ± 0.2 ms [User: 0.9 ms, System: 0.3 ms]
Range (min … max): 0.8 ms … 2.1 ms 1847 runs
Benchmark 4: ./nim/kal
Time (mean ± σ): 1.6 ms ± 0.3 ms [User: 1.0 ms, System: 0.4 ms]
Range (min … max): 0.9 ms … 4.3 ms 1941 runs
Benchmark 5: ./v/kal
Time (mean ± σ): 2.6 ms ± 0.4 ms [User: 1.3 ms, System: 1.0 ms]
Range (min … max): 1.8 ms … 3.9 ms 1218 runs
Summary
'./nelua-2/kal' ran
1.15 ± 0.29 times faster than './nim/kal'
1.21 ± 0.29 times faster than './nelua-1/kal'
1.90 ± 0.44 times faster than './v/kal'
2.02 ± 0.52 times faster than './go/kal'
Compile-speed comparison
Benchmark 1: cd go; make
Time (abs ≡): 137.3 ms [User: 82.5 ms, System: 82.2 ms]
Benchmark 2: cd nelua-1; nelua --cc=tcc -o kal -C kal.nelua
Time (abs ≡): 508.5 ms [User: 464.8 ms, System: 43.6 ms]
Benchmark 3: cd nelua-2; nelua --cc=tcc -o kal -C kal.nelua
Time (abs ≡): 659.0 ms [User: 601.2 ms, System: 55.8 ms]
Benchmark 4: cd nim; nim c kal.nim
Time (abs ≡): 1.745 s [User: 2.513 s, System: 0.334 s]
Benchmark 5: cd v; v kal.v
Time (abs ≡): 478.9 ms [User: 503.6 ms, System: 74.8 ms]
Summary
'cd go; make' ran
3.49 times faster than 'cd v; v kal.v'
3.70 times faster than 'cd nelua-1; nelua --cc=tcc -o kal -C kal.nelua'
4.80 times faster than 'cd nelua-2; nelua --cc=tcc -o kal -C kal.nelua'
12.71 times faster than 'cd nim; nim c kal.nim'