测试代码: C# Release 未优化 class Program { static long counter = 0; static void Main(string[] args) { for (int m = 0; m < 100; m++) { Stopwatch s = new Stopwatch(); s.Start(); for (long i = 0; i < 200000000; i++) { counter = counter * 2 + 3; } s.Stop(); C…
今天笔试遇到一个代码题,要求写一个开平方算法,回来发现了雷神之锤里的一段神代码: float Q_rsqrt( float number ) { long i; float x2, y; const float threehalfs = 1.5F; x2 = number * 0.5F; y = number; i = * ( long * ) &y; // evil floating point bit level hacking i = ); // what the fuck? y = *…