As shown in many other threads, you can get the same speed in Nim as in C or 
Assembly, especially for scientific computing:

  * [https://forum.nim-lang.org/t/5124](https://forum.nim-lang.org/t/5124)
  * my experiments for Project Picasso: 
[https://github.com/mratsim/weave/tree/master/benchmarks/fibonacci](https://github.com/mratsim/weave/tree/master/benchmarks/fibonacci)
 ([https://forum.nim-lang.org/t/5083)](https://forum.nim-lang.org/t/5083\)).
  * Matrix Multiplication in pure Nim vs expert-tuned Assembly libraries from 
Intel and others: 
[https://github.com/numforge/laser/blob/2f619fdbb2496aa7a5e5538035a8d42d88db8c10/benchmarks/gemm/gemm_bench_float32.nim#L418-L432](https://github.com/numforge/laser/blob/2f619fdbb2496aa7a5e5538035a8d42d88db8c10/benchmarks/gemm/gemm_bench_float32.nim#L418-L432)



Unfortunately, it is also as slow as C if you use strutils for naive string 
processing due to plenty of intermediate allocations, and the code that tends 
to loop over and over on the same string.

A way to fix that would be to have a library in the spirit of 
[zero-functional]([https://github.com/zero-functional/zero-functional](https://github.com/zero-functional/zero-functional))
 but specialized for strings. Temporary immutable allocations could use alloca 
to avoid stressing the GC (or newruntime could do that optimization).

I see multiple potential ways to implement that in an efficient and extensible 
manner if someone wants to explore it:

  * via a backend similar to [D 
ranges]([https://dlang.org/phobos/std_range.html](https://dlang.org/phobos/std_range.html))
 or [C++20 
ranges]([https://en.cppreference.com/w/cpp/ranges)](https://en.cppreference.com/w/cpp/ranges\)),
 see proof of concept by @timotheecour: 
[https://github.com/timotheecour/vitanim/tree/master/drange](https://github.com/timotheecour/vitanim/tree/master/drange)
  * via a state machine, similar to Nim inline iterators or Rust inline 
iterators. This involves lots of compile-time machinery.
  * in a functional way:
    * transducers: 
[http://sixty-north.com/blog/deriving-transducers-from-first-principles.html](http://sixty-north.com/blog/deriving-transducers-from-first-principles.html)
    * catamorphisms: 
[https://medium.com/@olxc/catamorphisms-and-f-algebras-b4e91380d134](https://medium.com/@olxc/catamorphisms-and-f-algebras-b4e91380d134)
    * others (?)


Reply via email to