Last active
December 27, 2015 13:39
-
-
Save daramkun/7335191 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| class Program | |
| { | |
| const int MAX_TEST = 100; | |
| const int MAX_PHASE = 10; | |
| const int MAX_LOOP = 10000000; | |
| public static void Main ( string [] args ) | |
| { | |
| Console.WriteLine ( "========================================" ); | |
| Console.WriteLine ( "* OS: {0} {1}", Environment.OSVersion.Platform, | |
| Environment.OSVersion.VersionString ); | |
| Console.WriteLine ( "* Is 64bit OS? {0}", Environment.Is64BitOperatingSystem ); | |
| Console.WriteLine ( "========================================" ); | |
| int prefixWon = 0, postfixWon = 0; | |
| bool [] patternOfWon = new bool [ MAX_TEST ]; | |
| for ( int k = 0; k < MAX_TEST; ++k ) | |
| { | |
| Console.WriteLine ( "Performance Test of {0}", k + 1 ); | |
| Console.WriteLine ( "========================================" ); | |
| Console.WriteLine ( "++i Performance Test:" ); | |
| TimeSpan prefixTimeSpan = new TimeSpan (); | |
| for ( int i = 0; i < MAX_PHASE; ++i ) | |
| { | |
| TimeSpan startTimeSpan = DateTime.Now.TimeOfDay; | |
| for ( int j = 0; j < MAX_LOOP; ++j ) | |
| ; | |
| TimeSpan endTimeSpan = DateTime.Now.TimeOfDay; | |
| prefixTimeSpan += ( endTimeSpan - startTimeSpan ); | |
| } | |
| Console.WriteLine ( "Total of ++i: {0}", prefixTimeSpan ); | |
| Console.WriteLine ( "----------------------------------------" ); | |
| Console.WriteLine ( "i++ Performance Test:" ); | |
| TimeSpan postfixTimeSpan = new TimeSpan (); | |
| for ( int i = 0; i < MAX_PHASE; ++i ) | |
| { | |
| TimeSpan startTimeSpan = DateTime.Now.TimeOfDay; | |
| for ( int j = 0; j < MAX_LOOP; j++ ) | |
| ; | |
| TimeSpan endTimeSpan = DateTime.Now.TimeOfDay; | |
| postfixTimeSpan += ( endTimeSpan - startTimeSpan ); | |
| } | |
| Console.WriteLine ( "Total of i++: {0}", postfixTimeSpan ); | |
| Console.WriteLine ( "----------------------------------------" ); | |
| Console.Write ( "Test {0} is won of ", k ); | |
| ConsoleColor backupColor = Console.ForegroundColor; | |
| if ( postfixTimeSpan > prefixTimeSpan ) | |
| { | |
| Console.ForegroundColor = ConsoleColor.DarkBlue; | |
| Console.WriteLine ( "prefix" ); | |
| patternOfWon [ k ] = true; | |
| ++prefixWon; | |
| } | |
| else | |
| { | |
| Console.ForegroundColor = ConsoleColor.DarkRed; | |
| Console.WriteLine ( "postfix" ); | |
| patternOfWon [ k ] = false; | |
| ++postfixWon; | |
| } | |
| Console.ForegroundColor = backupColor; | |
| Console.WriteLine ( "========================================" ); | |
| } | |
| Console.WriteLine ( " Prefix: {0}", prefixWon ); | |
| Console.WriteLine ( "Postfix: {0}", postfixWon ); | |
| ConsoleColor backupColor2 = Console.BackgroundColor; | |
| foreach ( bool won in patternOfWon ) | |
| { | |
| Console.BackgroundColor = ( won ) ? ConsoleColor.DarkBlue : ConsoleColor.DarkRed; | |
| Console.Write ( " " ); | |
| } | |
| Console.BackgroundColor = backupColor2; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment