1 /*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Francis Giraldeau - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.perf
.synchronization
;
15 import org
.eclipse
.linuxtools
.tmf
.core
.synchronization
.ITmfTimestampTransform
;
16 import org
.eclipse
.linuxtools
.tmf
.core
.synchronization
.TimestampTransformFactory
;
17 import org
.eclipse
.test
.performance
.Dimension
;
18 import org
.eclipse
.test
.performance
.Performance
;
19 import org
.eclipse
.test
.performance
.PerformanceMeter
;
20 import org
.junit
.Test
;
23 * Test the performance of linear transforms classes
25 * @author Francis Giraldeau
27 public class TimestampTransformBenchmark
{
29 private static final String TEST_ID
= "org.eclipse.linuxtools#Trace synchronization#";
30 private static final String TEST_SUMMARY
= "Timestamp Transform: ";
32 /** Number of transformations done for each transform: 50 millions */
33 private static final long NB_TRANSFORMATIONS
= 50000000L;
36 * Test the timestamp transform performances
39 public void testTimestampTransformPerformance() {
40 ITmfTimestampTransform transform
= TimestampTransformFactory
.getDefaultTransform();
41 doTimestampTransformRun("Identity transform", transform
, 10);
43 transform
= TimestampTransformFactory
.createWithOffset(123456789);
44 doTimestampTransformRun("Transform with offset", transform
, 10);
46 transform
= TimestampTransformFactory
.createLinear(Math
.PI
, 1234);
47 doTimestampTransformRun("Linear transform", transform
, 5);
49 transform
= TimestampTransformFactory
.createLinear(10000.1234545565635, -4312278758437L);
50 doTimestampTransformRun("Linear transform with larger slope and negative offset", transform
, 5);
53 private static void doTimestampTransformRun(String testName
, ITmfTimestampTransform xform
, long loopCount
) {
54 Performance perf
= Performance
.getDefault();
55 PerformanceMeter pm
= perf
.createPerformanceMeter(TEST_ID
+ testName
);
56 perf
.tagAsSummary(pm
, TEST_SUMMARY
+ testName
, Dimension
.CPU_TIME
);
58 for (int x
= 0; x
< loopCount
; x
++) {
60 * We use timestamps with values in the order of 10^18, which about
61 * corresponds to timestamps in nanoseconds since epoch
63 long time
= (long) Math
.pow(10, 18);
66 * Apply the timestamp transform NB_TRANSFORMATIONS times, with
67 * timestamps incremented by 200 each time
69 for (long i
= 0; i
< NB_TRANSFORMATIONS
; i
++) {
70 xform
.transform(time
);