Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- class Program
- {
- static void Main()
- {
- for (int i = 0; i < 10; i++)
- {
- RunTest();
- }
- }
- private static void RunTest()
- {
- const long cnt = 1000000000;
- var time1 = Test1(cnt);
- var time2 = Test2(cnt);
- Console.WriteLine($"Done in: {time1} vs {time2} diff: {time1 - time2}");
- }
- private static TimeSpan Test1(long cnt)
- {
- var v = 1;
- var timer = Stopwatch.StartNew();
- for (long i = cnt; i != 0; i--)
- {
- v = RotateBit(v);
- }
- timer.Stop();
- return timer.Elapsed;
- }
- private static TimeSpan Test2(long cnt)
- {
- var v = 1;
- var timer = Stopwatch.StartNew();
- for (long i = cnt; i != 0; i--)
- {
- v = RotateBit(v);
- }
- timer.Stop();
- return timer.Elapsed;
- }
- private static int RotateBit(int v)
- {
- v = v << 1;
- if ((v & 0b0000_1111) == 0)
- {
- v = 1;
- }
- return v;
- }
- }
Add Comment
Please, Sign In to add comment