Last active
March 23, 2022 06:10
-
-
Save kuenishi/b0c5316992e64d51796158d78b85c7e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ java HelloWorld | |
5.316 seconds for 1000000000 iteration: 188111.36192626035 Kcalls/sec | |
2.866 seconds for 10000000 iteration: 3489.183531053733 Kcalls/sec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HelloWorld { | |
public static void main(String[] args) { | |
bench1(); | |
bench2(); | |
} | |
static void bench1() { | |
long repeat = 1000000000L; | |
long start = java.lang.System.currentTimeMillis(); | |
for (long i = 0; i < repeat; i++) { | |
Long.toHexString(i); | |
} | |
long end = java.lang.System.currentTimeMillis(); | |
double duration = (end - start) / 1000.0; //seconds | |
System.out.println(duration + " seconds for " + repeat + " iteration: " + repeat / 1000.0 / duration + " Kcalls/sec"); | |
} | |
static void bench2() { | |
long repeat = 10000000L; | |
long start = java.lang.System.currentTimeMillis(); | |
for (long i = 0; i < repeat; i++) { | |
String.format("%016X", i); | |
} | |
long end = java.lang.System.currentTimeMillis(); | |
double duration = (end - start) / 1000.0; //seconds | |
System.out.println(duration + " seconds for " + repeat + " iteration: " + repeat / 1000.0 / duration + " Kcalls/sec"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment