So, I'm not able to edit the original post myself, but I want new readers to 
get good info more quickly, which means Zerbina's post and others, rather than 
my OP.

If I were able to contact an admin, I'd ask that the below be pasted at the top 
of the OP, subject of course to corrections and improvements.

\--- BEGIN

EDIT: Some good news: the concerns raised in this post have been addressed. See 
post by Zerbina below.

Nim resizable arrays, whether native in the form of sequences or non-native in 
the form of imported C++ "std::vector"s (via the cppstl library), can be just 
as fast as Nim fixed-length arrays, which can be expected to be just as fast as 
C arrays. Pointer indirection also isn't slower.

The slow-down that prompted the OP's concern was, instead - as pointed out by 
Zerbina - due to: Sequences being used outside of a procedure (at the module 
level), which made them globals, which placed them in the application's data 
section. This defeats automatic vectorization (the usage of SIMD assembly), by 
at least the tested C and C++ compilers, for - apparently - things other than 
than fixed arrays.

So, put your sequences in a procedure.

Do it like Dennis Felsing: 
<https://hookrace.net/blog/what-is-special-about-nim/#nim-runtime-26-s> (and, 
when you've got some time to invest, here's W. Gordon Goodsman working Nim 
hardcore on the same problem 
<https://nim-lang.org/blog/2021/07/28/Nim-Efficient-Expressive-Elegant-Benchmarking.html>)

Also consider turning off bounds-checking (again, see Zerbina's post for 
details). Remember that this is only suitable for well-tested code blocks that 
you absolutely need to be fast; Nim defaults to automatic bounds-checks for 
good reasons!

\--- ORIGINAL POST FOLLOWS ---

Reply via email to