4 ms·
It depends. For example, you can verbosely write a loop to copy data from one array to another, or you can use memcpy. The later is typically implemented as h
by dgoldstein0 7y ago
It depends. For example, you can verbosely write a loop to copy data from one array to another, or you can use memcpy. The later is typically implemented as hand optimised assembly - it's a pretty small number of operations in x86_64. The former - maybe the compiler optimizes, maybe it doesn't. If it does optimize it, it's definitely more complexity in the compiler and slows it down.
In general having some higher level, well optimized helpers can certainly reduce verbosity and increase speed. That said, some types of verbosity just make the programmer write what the compiler would translate to anyway. Or can end up being unnecessary - e.g. a strongly typed language with no inference certain slows the programmer with no effect on the program (though maybe an effect on the type checker).
- im3w1l 7y agoA fast memcpy used to be complicated to implement but these days I heard a simple rep movsb will do the trick. This assumes that the source register points to source, destination register points to destination and counter register is set to number of bytes to copy.
- pizlonator 7y agoI wish that was true but my data says it isn't: - A verbose SIMD copy loop is often faster even on modern Intel CPUs that have the more modern rep implementation. - A simple byte copy loop will beat both SIMD and rep when you're copying smaller amounts at a time.