News for hackers. Stuff that matters.
Re:SICP Goodness – Why you don't need looping constructs by jstimpfle on Friday June 29, 2018 @10:23AM (#17424670)
> I’ve periodically done microbenchmarks of inner loops over the years and the various gcc outputs of the c++ loop functions are always performing slightly better than if I hand rolled. Perhaps with gcc7 or clang this is different.

Any code examples?

What I was thinking of is hand-rolling

    for (a; b; c;)
        BODY
to

    a;
  
    loop:
    if (!b)
        goto out;
    BODY
    c;
    goto loop;
    
    out:
    ...
Re:SICP Goodness – Why you don't need looping constructs by goalieca on Friday June 29, 2018 @10:56AM (#17424875)
My thought about hand rolling is that any loop is hand-rolled if I tell the compiler how to do things (ie not declarative). Writing out a for loop with an s+=*p++ for summing the elements in a vector is hand rolling a “reduce”. You can add all the tricks you want like changing the stride, doing simd, prefetching, but I’ve learned to let the compiler or the math/data library do its job.

For small data (MB) the compiler or library can parallelize things nicely. Bigger data (TB+) can be chewed threw by using MPI aware libraries that optimize and schedule and everything. Database work is already declarative because SQL is just so awesome. C# and java now handle fusion and streams more nicely and c++ can in-line and r-value a lot of overhead away.

Re:SICP Goodness – Why you don't need looping constructs by jstimpfle on Friday June 29, 2018 @11:29AM (#17425062)
Yeah you need to be careful what kind of iteration you do. Modifying pointers is likely problematic. Iterating over a range of integers on the other hand should be easy to optimize.

In most cases, it shouldn't matter and it's much more important to think about the data accesses, due to the relative slowness of memory.