-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaBenchmark.java
More file actions
32 lines (26 loc) · 1.17 KB
/
JavaBenchmark.java
File metadata and controls
32 lines (26 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.regex.Pattern;
public class JavaBenchmark {
public static void main(String[] args) throws Exception {
long t0 = System.nanoTime();
var now = ZonedDateTime.now(ZoneId.systemDefault());
var fmt = DateTimeFormatter.ISO_ZONED_DATE_TIME;
var s = fmt.format(now);
var p = Pattern.compile("([0-9T:\\-+.]+)\\[(.+)]");
var m = p.matcher(s);
String zone = m.find() ? m.group(2) : "UTC";
var list = new ArrayList<>(List.of("alpha", "beta", zone, UUID.randomUUID().toString()));
Collections.sort(list);
String joined = String.join("|", list);
var md = MessageDigest.getInstance("SHA-256");
byte[] dig = md.digest(joined.getBytes(StandardCharsets.UTF_8));
BigInteger prime = BigInteger.probablePrime(1024, new Random(42));
long tookMs = (System.nanoTime() - t0) / 1_000_000;
System.out.println("OK " + dig[0] + " " + prime.bitLength() + " took=" + tookMs + "ms");
}
}