Skip to content

Commit

Permalink
to stringbuffer-perf, add comparison at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
texadactyl committed Aug 8, 2024
1 parent 29173a9 commit 803768c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions tests/stringbuffer-perf/main.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public static void main(String[] args) {
runBuilder();
}
long t2 = System.currentTimeMillis();
double secs_overall = (double) (t2 - t1) / 1000.0;
System.out.printf("runBuilder overall elapsed time = %.3f seconds\n", secs_overall);
double secs_builder = (double) (t2 - t1) / 1000.0;
System.out.printf("runBuilder overall elapsed time = %.3f seconds\n", secs_builder);

// StringBuffer
System.out.println("runBuffer start .....");
Expand All @@ -65,7 +65,17 @@ public static void main(String[] args) {
runBuffer();
}
t2 = System.currentTimeMillis();
secs_overall = (double) (t2 - t1) / 1000.0;
System.out.printf("runBuffer overall elapsed time = %.3f seconds\n", secs_overall);
double secs_buffer = (double) (t2 - t1) / 1000.0;

System.out.printf("runBuffer overall elapsed time = %.3f seconds\n", secs_buffer);
if (secs_builder > 0.0001) {
if (secs_builder < secs_buffer) {
double pct = 100.0 * (secs_buffer - secs_builder) / secs_builder;
System.out.printf("runBuffer runs %.1f pct slower than runBuilder\n", pct);
} else {
double pct = 100.0 * (secs_builder - secs_buffer) / secs_builder;
System.out.printf("runBuffer runs %.1f pct faster than runBuilder\n", pct);
}
}
}
}

0 comments on commit 803768c

Please sign in to comment.