Devblog:

Sometimes your intuition is just totally wrong.

A while back I wrote a fun little post about different functions for computing the chance to gain skill. You might recall that your humble devblogger suggested that the natural logarithm would be slow and unwieldy when trying to approximate the complementary error function, and that a polynomial solution was better.

Well, I actually did some benchmarking today on my thinkpad (Sandy Bridge i7, 8GB). Turns out that C# doesn't even have an implementation for erfc() so I just tested the other three:

jester@thinkpad:~/documents/code/csharp$ mono benchmark.exe 
Iterating to 1
Testing Cosine method...
Done.  Iterations:  1, Elapsed:  9.051ms
Testing Polynomial method...
Done.  Iterations:  1, Elapsed:  0.037ms
Testing Logarithm method...
Done.  Iterations:  1, Elapsed:  0.012ms
Iterating to 10
Testing Cosine method...
Done.  Iterations:  10, Elapsed:  0.015ms
Testing Polynomial method...
Done.  Iterations:  10, Elapsed:  0.027ms
Testing Logarithm method...
Done.  Iterations:  10, Elapsed:  0.034ms
Iterating to 100
Testing Cosine method...
Done.  Iterations:  100, Elapsed:  0.024ms
Testing Polynomial method...
Done.  Iterations:  100, Elapsed:  0.094ms
Testing Logarithm method...
Done.  Iterations:  100, Elapsed:  0.025ms
Iterating to 1000
Testing Cosine method...
Done.  Iterations:  1000, Elapsed:  0.138ms
Testing Polynomial method...
Done.  Iterations:  1000, Elapsed:  0.681ms
Testing Logarithm method...
Done.  Iterations:  1000, Elapsed:  0.13ms
Iterating to 10000
Testing Cosine method...
Done.  Iterations:  10000, Elapsed:  1.284ms
Testing Polynomial method...
Done.  Iterations:  10000, Elapsed:  5.977ms
Testing Logarithm method...
Done.  Iterations:  10000, Elapsed:  1.022ms
Iterating to 100000
Testing Cosine method...
Done.  Iterations:  100000, Elapsed:  11.411ms
Testing Polynomial method...
Done.  Iterations:  100000, Elapsed:  46.885ms
Testing Logarithm method...
Done.  Iterations:  100000, Elapsed:  6.943ms
Iterating to 1000000
Testing Cosine method...
Done.  Iterations:  1000000, Elapsed:  69.204ms
Testing Polynomial method...
Done.  Iterations:  1000000, Elapsed:  225.343ms
Testing Logarithm method...
Done.  Iterations:  1000000, Elapsed:  34.558ms
Iterating to 10000000
Testing Cosine method...
Done.  Iterations:  10000000, Elapsed:  420.749ms
Testing Polynomial method...
Done.  Iterations:  10000000, Elapsed:  2069.943ms
Testing Logarithm method...
Done.  Iterations:  10000000, Elapsed:  346.445ms
Iterating to 100000000
Testing Cosine method...
Done.  Iterations:  100000000, Elapsed:  4179.357ms
Testing Polynomial method...
Done.  Iterations:  100000000, Elapsed:  20475.724ms
Testing Logarithm method...
Done.  Iterations:  100000000, Elapsed:  3452.435ms

Ignore that first aberrant result - several orders of magnitude slower than the next trial. That's not a typo, just a small bug in the benchmarking code that I wrote. The extra delay is due to the constructor for DateTime being called (and probably nothing being cached yet). In reality, that first calculation takes only 12 microseconds or so.

You can see that the Polynomial method is significantly slower, taking upwards of 20 seconds to crunch that equation 100 million times. I was surprised to see the logarithm method run almost 7 times faster! The default RunUO method is just a little bit slower than the Cosine method here.

Just goes to show that it's better not to assume, especially when it comes to software performance. This covers the probability to gain for a single attempt: later on in a different post I'll examine how that translates to what the player experiences.