Search in sources :

Example 1 with SystemTimeSource

use of com.ms.silverking.time.SystemTimeSource in project SilverKing by Morgan-Stanley.

the class TimeTest method time.

public static void time() {
    Stopwatch swSystem;
    Stopwatch swNanos;
    Stopwatch swTimerDriven;
    Stopwatch swTimerDrivenDirect;
    TimerDrivenTimeSource ts;
    int reps = 1000000;
    long result;
    TimeTest timeTest;
    RelNanosTimeSource relNanosTimeSource;
    AbsMillisTimeSource absMillisTimeSource;
    absMillisTimeSource = new SystemTimeSource();
    timeTest = new TimeTest();
    result = 0;
    swSystem = new SimpleNamedStopwatch("System");
    for (int i = 0; i < reps; i++) {
        // result += System.currentTimeMillis();
        result += absMillisTimeSource.absTimeMillis();
    }
    swSystem.stop();
    swNanos = new SimpleNamedStopwatch("Nanos");
    for (int i = 0; i < reps; i++) {
        result += System.nanoTime();
    }
    swNanos.stop();
    relNanosTimeSource = new TimerDrivenTimeSource();
    swTimerDriven = new SimpleNamedStopwatch("TimerDriven");
    for (int i = 0; i < reps; i++) {
        // System.out.println(timeTest.getElapsed());
        result += relNanosTimeSource.relTimeNanos();
    }
    swTimerDriven.stop();
    ts = new TimerDrivenTimeSource();
    swTimerDrivenDirect = new SimpleNamedStopwatch("TimerDrivenDirect");
    for (int i = 0; i < reps; i++) {
        // System.out.println(timeTest.getElapsed());
        result += ts.relTimeNanos();
    }
    swTimerDrivenDirect.stop();
    System.out.println(result + "\n");
    displayRate(swSystem, reps);
    displayRate(swNanos, reps);
    displayRate(swTimerDriven, reps);
    displayRate(swTimerDrivenDirect, reps);
}
Also used : TimerDrivenTimeSource(com.ms.silverking.time.TimerDrivenTimeSource) SimpleNamedStopwatch(com.ms.silverking.time.SimpleNamedStopwatch) Stopwatch(com.ms.silverking.time.Stopwatch) SimpleNamedStopwatch(com.ms.silverking.time.SimpleNamedStopwatch) SystemTimeSource(com.ms.silverking.time.SystemTimeSource) AbsMillisTimeSource(com.ms.silverking.time.AbsMillisTimeSource) RelNanosTimeSource(com.ms.silverking.time.RelNanosTimeSource)

Aggregations

AbsMillisTimeSource (com.ms.silverking.time.AbsMillisTimeSource)1 RelNanosTimeSource (com.ms.silverking.time.RelNanosTimeSource)1 SimpleNamedStopwatch (com.ms.silverking.time.SimpleNamedStopwatch)1 Stopwatch (com.ms.silverking.time.Stopwatch)1 SystemTimeSource (com.ms.silverking.time.SystemTimeSource)1 TimerDrivenTimeSource (com.ms.silverking.time.TimerDrivenTimeSource)1