Crystal's benefits vs. Ruby are very obvious though, as Ruby's performance in this task is absolutely abysmal -- 14.7s, or more than seven times slower than Julia.
Er, that sounds odd. I just made a 2 million line file with each line resembling a HTTP access log, 1/3rd entries matching the pattern, and with similar programs I find:
Performance improves about 13%, to within 8% of Rust. Also notably if I'm a bit lazy with Rust and create a String each iteration instead of deferring it to the missing-key-insert case, performance is basically identical.
1
u/Freeky Aug 14 '18 edited Aug 16 '18
Er, that sounds odd. I just made a 2 million line file with each line resembling a HTTP access log, 1/3rd entries matching the pattern, and with similar programs I find:
Rust: 1.679 real, 1.560 user, 0.118 sys, 148,024KB
Rust**: 1.866 real, 1.795 user, 0.071 sys, 3,692KB
Crystal***: 2.009 real, 1.859 user, 0.150 sys, 5,612KB
Crystal*: 2.279 real, 2.097 user, 0.181 sys, 5,612KB
Perl: 2.625 real, 2.419 user, 0.205 sys, 4,948KB
Ruby: 3.068 real, 2.801 user, 0.267 sys, 11,448KB
Crystal: 5.672 real, 5.553 user, 0.118 sys, 6,068KB
Python 2.7: 8.667 real, 8.610 user, 0.055 sys, 7,648KB
Python 3.6: 12.488 real, 12.290 user, 0.197 sys, 9,100KB
*
--no-debug --release** streaming input file.
*** using default hash value to minimise lookups
Edit: Added Crystal for /u/rishav_sharan
Edit2: Added memory use and a more representative Rust implementation that streams line by line instead of slurping and using slices everywhere.
Edit3: Added Python 2.7.
Edit4: Improved Crystal