Benchmarking small code samples in C#, can this implementation be improved?

Here is the modified function: as recommended by the community, feel free to amend this its a community wiki. static double Profile(string description, int iterations, Action func) { //Run at highest priority to minimize fluctuations caused by other processes/threads Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High; Thread.CurrentThread.Priority = ThreadPriority.Highest; // warm up func(); var watch = new Stopwatch(); // … Read more

Getting total row count from OFFSET / FETCH NEXT

I encountered some performance issues using the COUNT() OVER() method. (I’m not sure if it was the server as it took 40 seconds to return 10 records and then later didn’t have any issues.) This technique worked under all conditions without having to use COUNT() OVER() and accomplishes the same thing: DECLARE @PageSize INT = … Read more

Why is Go so slow (compared to Java)?

The 6g and 8g compilers are not particularly optimising, so the code they produce isn’t particularly fast. They’re designed to run fast themselves and produce code that’s OK (there is a bit of optimisation). gccgo uses GCC’s existing optimisation passes, and might provide a more pointful comparison with C, but gccgo isn’t feature-complete yet. Benchmark … Read more

In C++, should I bother to cache variables, or let the compiler do the optimization? (Aliasing)

At first glance, I thought the compiler could generate equivalent assembly for both versions with optimization flags activated. When I checked it, I was surprised to see the result: Source unoptimized.cpp note: this code is not meant to be executed. struct bitmap_t { long long width; } bitmap; int main(int argc, char** argv) { for … Read more

Fastest way to check if a string matches a regexp in ruby?

Starting with Ruby 2.4.0, you may use RegExp#match?: pattern.match?(string) Regexp#match? is explicitly listed as a performance enhancement in the release notes for 2.4.0, as it avoids object allocations performed by other methods such as Regexp#match and =~: Regexp#match? Added Regexp#match?, which executes a regexp match without creating a back reference object and changing $~ to … Read more