Last active
August 29, 2015 14:14
-
-
Save disktnk/c40690637a24ea5906f3 to your computer and use it in GitHub Desktop.
java7までの処理計測と、java8からの処理計測
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
import java.time.Duration; | |
import java.time.Instant; | |
public class DurationSample { | |
public static void main(String[] args) { | |
{ // ~java1.7 | |
long start = System.nanoTime(); | |
someAlgorithm(); | |
long end = System.nanoTime(); | |
double elapse = (end - start) / 1000000.0; | |
System.out.println(elapse + "[ms]"); | |
} | |
{ // java1.8~ | |
Instant start = Instant.now(); | |
someAlgorithm(); | |
Instant end = Instant.now(); | |
Duration elapse = Duration.between(start, end); | |
System.out.println(elapse.toNanos() / 1000000.0 + "[ms]"); | |
} | |
} | |
private static void someAlgorithm() { | |
// some algorithm | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment