claunia / plist-cil

C#/.NET parser for Apple and GnuStep Property List (aka plist), based on Java's dd-plist
Other
56 stars 17 forks source link

Use 1 << exp instead of Math.Pow(2, exp) #59

Closed qmfrederik closed 5 years ago

qmfrederik commented 5 years ago

Math.Pow(double, double) is a relatively expensive operation (since it can take an arbitrary exponent). For powers of two, byteshift operators are much faster.

Benchmark.NET can't actually measure the time it takes to do 1 << exp, but Math.Pow(2, exp) takes about 40 nanoseconds. It was actually slow enough to show up in some of the performance traces we took.