Created
April 4, 2017 14:19
-
-
Save wfxr/73271f396619d4f60dc83157d32898c2 to your computer and use it in GitHub Desktop.
Java benchmark util.
This file contains hidden or 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
| package com.zmeng.rinascimento.pascal.common.testutil; | |
| import java.util.function.Supplier; | |
| import static java.lang.System.currentTimeMillis; | |
| /** | |
| * Created by Wenxuan-Zhang on 2017/3/20. | |
| * Email: zhangwenxuan@zmeng123.com | |
| */ | |
| public class Benchmark { | |
| public static <T> T measureTime(Supplier<T> task, String taskName) { | |
| // JVM预热 | |
| task.get(); | |
| System.out.printf("Task [%s] start...\n", taskName); | |
| final long start = currentTimeMillis(); | |
| T result = task.get(); | |
| System.out.printf("Task [%s] completed using %dms.\n", taskName, currentTimeMillis() - start); | |
| return result; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment