https://github.com/zoomrmc/countwords_nim
Counting words with Nim
https://github.com/zoomrmc/countwords_nim
counting-words nim optimization
Last synced: about 2 months ago
JSON representation
Counting words with Nim
- Host: GitHub
- URL: https://github.com/zoomrmc/countwords_nim
- Owner: ZoomRmc
- License: mit
- Created: 2021-03-31T09:42:57.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-16T08:53:12.000Z (about 3 years ago)
- Last Synced: 2024-06-21T18:05:39.472Z (11 months ago)
- Topics: counting-words, nim, optimization
- Language: Nim
- Homepage:
- Size: 1.29 MB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Beating Go in counting words with Nim.
See the full original article for context and background: [https://benhoyt.com/writings/count-words/](https://benhoyt.com/writings/count-words/)
Original repository [benhoyt/countwords](https://github.com/benhoyt/countwords) is closed for further contributions.
## Details and discussion
See the nim-lang forum thread: https://forum.nim-lang.org/t/7926⚠️ There's a [separate branch with a faster hashing hack](https://github.com/ZoomRmc/countwords_nim/tree/hashrearhatch) applied. See details in the commit messages.
## Status:
🍾*Mission accomplished!* Currently faster than Go by a factor dependent on input size:
```
x1: 19%
x10: 3.7%
x50: 1.7%
```Code tries to stay close to the same basic algorithm used by most optimized versions from the original repo.
Probably no point running with `--gc:` other than `arc` or `orc`. Last comparison of various included garbage collectors:
```
arc/orc: 5.6s
boehm: 5.7s
markAndSweep: 5.9s
regions: 6.1s
refc: 6.4s
```## Timing the current implementation
To get statistically significant result measure multiple times or use specialized tools like [hyperfine](https://github.com/sharkdp/hyperfine)Required:
- Bash
- Go
- Nim
- Writable /tmp/```bash
./test.sh
```To just build the Nim version:
```bash
nim c --gc:arc -d:danger --passC:"-flto" --passL:"-flto" -o:optimized_nim optimized.nim
```## Credits
The included Go version: [Ben Hoyt](https://github.com/benhoyt) and [Miguel Angel](https://github.com/ntrrg)## License
MIT