Skip to content

Instantly share code, notes, and snippets.

@wfxr
Created April 4, 2017 14:19
Show Gist options
  • Select an option

  • Save wfxr/73271f396619d4f60dc83157d32898c2 to your computer and use it in GitHub Desktop.

Select an option

Save wfxr/73271f396619d4f60dc83157d32898c2 to your computer and use it in GitHub Desktop.
Java benchmark util.
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