4 ms·
My Crystal test code with primes managed to run 4x faster than the D version and 1.15x faster then the Go version when built with the --release switch, but when
by petre 8y ago
My Crystal test code with primes managed to run 4x faster than the D version and 1.15x faster then the Go version when built with the --release switch, but when I ran it up to 100k it filled up all my 8GB of memory and started swapping. The D and Go versions run fine up to 100k without any issues and without filling up the memory. Running it up to 100k probably also causes integer overflow and I couldn't make the range iterations work with uint64 as I'm not quite familiar with the language.
Crystal https://p.thorsen.pm/f4b376d71d1a https://p.thorsen.pm/f4b376d71d1a
Dlang https://p.thorsen.pm/f5f7d6b09480 https://p.thorsen.pm/f5f7d6b09480
Golang https://p.thorsen.pm/369b79e836a8 https://p.thorsen.pm/369b79e836a8
- sam0x17 8y agoYou should definitely consider using Set(Int32) instead of Hash(Int32, Bool). Not sure why it is using so much RAM but I strongly encourage you to submit this as an issue on the crystal lang github.
- petre 8y agoThe problem is that not all the languages tested have a Set type. This is why all the implementations use a Hash or map or associative array type, which are roughly the same thing. Othwerwise we are comparing apples with oranges. I also refuse to use anything which is not included in the standard library. The program does really basic stuff, so all of its building blocks should be in the core language. This is why the Rust implementation is slower than D or Go - because it uses HashMap which is slower than D's associative arrays or Go's maps.
- petre 8y agoI reported it and it turns out that the integer overflow generated the memory consumption issue. After modifying the code it's speed is par with Go.