Example class for Graal. (#5486)
This commit is contained in:
parent
406d9c290d
commit
758648eb05
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user