1 // https://www.graalvm.org/22.1/examples/java-performance-examples/#streams-api-example 2 public class CountUppercase { 3 static final int ITERATIONS = Math.max(Integer.getInteger("iterations", 1), 1); 4 public static void main(String[] args) { 5 String sentence = String.join(" ", args); 6 for (int iter = 0; iter < ITERATIONS; iter++) { 7 if (ITERATIONS != 1) System.out.println("-- iteration " + (iter + 1) + " --"); 8 long total = 0, start = System.currentTimeMillis(), last = start; 9 for (int i = 1; i < 10_000_000; i++) { 10 total += sentence.chars().filter(Character::isUpperCase).count(); 11 if (i % 1_000_000 == 0) { 12 long now = System.currentTimeMillis(); 13 System.out.printf("%d (%d ms)%n", i / 1_000_000, now - last); 14 last = now; 15 } 16 } 17 System.out.printf("total: %d (%d ms)%n", total, System.currentTimeMillis() - start); 18 } 19 } 20 }