SETUP:
Install nim
REPO_PATH=$HOME/repos
cd $REPO_PATH
git clone git@github.com:nim-lang/Nim.git
cd Nim
./build_all.sh
# add to your path - change to bashrc if you use bash
echo "export PATH='${REPO_PATH}/Nim/bin/:\$PATH'" >> ~/.zshrc
Now go to this repo location and run nimble install
- nimble is used to
install cligen. With cligen, you have CLI
parsing based off function argument types - which is great for quick iteration
speed. There are alternatives to this library.
Notably, for this example, we could have used
commandLineParams()
from std/cmdline
BENCHMARK:
The below will compile the nim program & run hyperfine on it for you:
nim benchmarkNim
Result: 3.5 ms ± 4.1 ms
For reference, here is python:
nim benchmarkPy
Result: 32.3 ms ± 4.2 ms
Example benchmarks were run on an M1 Max.
RUN IT YOURSELF:
The below compiles and runs the program on the input
nim c -d:release -r parse_json.nim --inputFile wealth.json
or:
nim compile
nim runExample
see config.nims
for tasks