Part 97 Performance of a multithreaded program, performanceof
Class Program {static void Main (string [] args) {Stopwatch s = new Stopwatch (); s. start (); EvenNumbersSum (); OddNumbersSum (); s. stop (); Console. writeLine ("before using multiple threads" + s. elapsedMilliseconds); s = new Stopwatch (); s. start (); Thread t1 = new Thread (EvenNumbersSum); Thread t2 = new Thread (OddNumbersSum); t1.Start (); t2.Start (); t1.Join (); t2.Join (); s. stop (); Console. writeLine ("after using multiple threads" + s. elapsedMilliseconds);} public static void EvenNumbersSum () {double sum = 0; for (int I = 0; I <= 50000000; I ++) {if (I % 2 = 0) {sum + = I ;}} Console. writeLine ("sum =" + sum);} public static void OddNumbersSum () {double sum = 0; for (int I = 0; I <= 50000000; I ++) {if (I % 2 = 1) {sum + = I ;}} Console. writeLine ("sum =" + sum) ;}} View Code