Skip to content

Commit

Permalink
Example class for Graal. (eugenp#5486)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdjole authored and maibin committed Oct 29, 2018
1 parent 406d9c2 commit 758648e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions core-java-10/src/main/java/com/baeldung/graal/CountUppercase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.baeldung.graal;

public class CountUppercase {
static final int ITERATIONS = Math.max(Integer.getInteger("iterations", 1), 1);

public static void main(String[] args) {
String sentence = String.join(" ", args);
for (int iter = 0; iter < ITERATIONS; iter++) {
if (ITERATIONS != 1) System.out.println("-- iteration " + (iter + 1) + " --");
long total = 0, start = System.currentTimeMillis(), last = start;
for (int i = 1; i < 10_000_000; i++) {
total += sentence
.chars()
.filter(Character::isUpperCase)
.count();
if (i % 1_000_000 == 0) {
long now = System.currentTimeMillis();
System.out.printf("%d (%d ms)%n", i / 1_000_000, now - last);
last = now;
}
}
System.out.printf("total: %d (%d ms)%n", total, System.currentTimeMillis() - start);
}
}
}

0 comments on commit 758648e

Please sign in to comment.