Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package calculatempo;
- import java.lang.management.ThreadMXBean;
- import java.lang.management.ManagementFactory;
- /**
- *
- * @author Gilson
- */
- public class BenchMark {
- private long inicio = 0;
- private long fim = 0;
- //private long tempo = fim - inicio;
- public BenchMark() {
- inicio = 0;
- fim = 0;
- }
- public double getTempo() {
- return (fim - inicio);
- }
- public void reset() {
- inicio = 0;
- fim = 0;
- }
- public void startWatch() {
- inicio = System.nanoTime();
- }
- public void endWatch() {
- fim = System.nanoTime();
- }
- public void startCpu() {
- inicio = getCpuTime();
- }
- public void endCpu() {
- fim = getCpuTime();
- }
- /** Get CPU time in nanoseconds. */
- public long getCpuTime() {
- ThreadMXBean bean = ManagementFactory.getThreadMXBean();
- return bean.isCurrentThreadCpuTimeSupported()
- ? bean.getCurrentThreadCpuTime() : 0L;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement