X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.utils.datastructures%2Fsrc%2Forg%2Fsimantics%2Futils%2Fdatastructures%2FTimingUtil.java;fp=bundles%2Forg.simantics.utils.datastructures%2Fsrc%2Forg%2Fsimantics%2Futils%2Fdatastructures%2FTimingUtil.java;h=42eed9b89040873ef7d26a4cbe9e0cc3045420d7;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=ad9bb81296997ec84e6adaadedc482797c94b2ec;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/TimingUtil.java b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/TimingUtil.java index ad9bb8129..42eed9b89 100644 --- a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/TimingUtil.java +++ b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/TimingUtil.java @@ -1,69 +1,69 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.utils.datastructures; - -import java.io.PrintStream; -import java.util.concurrent.TimeUnit; - - -/** - * @author Tuukka Lehtonen - */ -public final class TimingUtil { - - public abstract static class NamedRunnable implements Runnable { - String name; - public NamedRunnable(String name) { - this.name = name; - } - @Override - public String toString() { - return name; - } - } - - public static class PrintCallback implements BinaryCallback { - String task; - PrintStream stream; - PrintCallback(String task) { - this(task, System.out); - } - PrintCallback(String task, PrintStream stream) { - this.task = task; - this.stream = stream; - } - @Override - public void run(Long arg1, TimeUnit arg2) { - stream.println(task + " took " + arg1 + " " + arg2.toString()); - } - }; - - public static void time(Runnable runnable) { - time(runnable, System.out); - } - - public static void time(Runnable runnable, PrintStream stream) { - time(runnable, TimeUnit.MILLISECONDS, new PrintCallback(runnable.toString(), stream)); - } - - public static void time(Runnable runnable, TimeUnit reportTimeUnit, PrintStream stream) { - time(runnable, reportTimeUnit, new PrintCallback(runnable.toString(), stream)); - } - - public static void time(Runnable runnable, TimeUnit reportTimeUnit, BinaryCallback result) { - long start = System.nanoTime(); - runnable.run(); - long end = System.nanoTime(); - result.run(reportTimeUnit.convert(end-start, TimeUnit.NANOSECONDS), reportTimeUnit); - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.utils.datastructures; + +import java.io.PrintStream; +import java.util.concurrent.TimeUnit; + + +/** + * @author Tuukka Lehtonen + */ +public final class TimingUtil { + + public abstract static class NamedRunnable implements Runnable { + String name; + public NamedRunnable(String name) { + this.name = name; + } + @Override + public String toString() { + return name; + } + } + + public static class PrintCallback implements BinaryCallback { + String task; + PrintStream stream; + PrintCallback(String task) { + this(task, System.out); + } + PrintCallback(String task, PrintStream stream) { + this.task = task; + this.stream = stream; + } + @Override + public void run(Long arg1, TimeUnit arg2) { + stream.println(task + " took " + arg1 + " " + arg2.toString()); + } + }; + + public static void time(Runnable runnable) { + time(runnable, System.out); + } + + public static void time(Runnable runnable, PrintStream stream) { + time(runnable, TimeUnit.MILLISECONDS, new PrintCallback(runnable.toString(), stream)); + } + + public static void time(Runnable runnable, TimeUnit reportTimeUnit, PrintStream stream) { + time(runnable, reportTimeUnit, new PrintCallback(runnable.toString(), stream)); + } + + public static void time(Runnable runnable, TimeUnit reportTimeUnit, BinaryCallback result) { + long start = System.nanoTime(); + runnable.run(); + long end = System.nanoTime(); + result.run(reportTimeUnit.convert(end-start, TimeUnit.NANOSECONDS), reportTimeUnit); + } + +}