Skip to content

Commit

Permalink
Added comparison of times at the end.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexNPavel committed Apr 6, 2015
1 parent a925696 commit 4fdfb9a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions ThreadedMerge/src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public class Main {
static int[] myStuff;
static int[] temp;
static long time;
static long time2;
static long singleThreadTime;
static long multiThreadTime;

public static void main(String[] args) {
int arraySize = 20000000;
Expand Down Expand Up @@ -49,8 +52,9 @@ public static void main(String[] args) {
e.printStackTrace();
}
}

System.out.println("First Time: " + (System.currentTimeMillis() - time));
time2 = System.currentTimeMillis();
System.out.println("First Time: " + (time2 - time));
multiThreadTime = time2 - time;
// System.out.println("New array "+Arrays.toString(myStuff));
for (int i = 0; i < myStuff.length; i++) {
myStuff[i] = new Random().nextInt(maxInt);
Expand All @@ -65,8 +69,11 @@ public static void main(String[] args) {
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Second Time: " + (System.currentTimeMillis() - time));
time2 = System.currentTimeMillis();
System.out.println("Second Time: " + (time2 - time));
singleThreadTime = time2 - time;
// System.out.println("New array "+Arrays.toString(myStuff));
System.out.println("MultiThreaded was " + ( (double) singleThreadTime / (double) multiThreadTime) + "x faster than SingleThreaded");
}

}

0 comments on commit 4fdfb9a

Please sign in to comment.