Skip to content

Commit 758648e

Browse files
cdjolemaibin
authored andcommitted
Example class for Graal. (eugenp#5486)
1 parent 406d9c2 commit 758648e

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.baeldung.graal;
2+
3+
public class CountUppercase {
4+
static final int ITERATIONS = Math.max(Integer.getInteger("iterations", 1), 1);
5+
6+
public static void main(String[] args) {
7+
String sentence = String.join(" ", args);
8+
for (int iter = 0; iter < ITERATIONS; iter++) {
9+
if (ITERATIONS != 1) System.out.println("-- iteration " + (iter + 1) + " --");
10+
long total = 0, start = System.currentTimeMillis(), last = start;
11+
for (int i = 1; i < 10_000_000; i++) {
12+
total += sentence
13+
.chars()
14+
.filter(Character::isUpperCase)
15+
.count();
16+
if (i % 1_000_000 == 0) {
17+
long now = System.currentTimeMillis();
18+
System.out.printf("%d (%d ms)%n", i / 1_000_000, now - last);
19+
last = now;
20+
}
21+
}
22+
System.out.printf("total: %d (%d ms)%n", total, System.currentTimeMillis() - start);
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)