blob: 9a6730ba859ec105e060eeb16d4068ac84c9a5eb [file] [log] [blame]
/*****************************************************************************
* Copyright (c) 2018 CEA LIST and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* CEA LIST - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.cdo.benchmarks.tests;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import org.eclipse.osgi.framework.util.ArrayMap;
import org.junit.Assert;
/**
* @author VL222926
*
*/
public class ExecutionTimeHelper {
public static final String STEP_1 = "Step 1 : Creating Model Set";
public static final String STEP_2 = "Step 2 : Creating elements";
public static final String STEP_3 = "Step 3 : Saving the model";
public static final String STEP_4 = "Step 4 : Accessing Element";
public static final String STEP_5 = "Step 5 : Accessing 5 000th Element";
public static final String STEP_6 = "Step 6 : Get stereotype application on 5 000th Element";
public static final String STEP_7 = "Step 7 : Add 100 elements to the root of the resource";
public static final String CDO_TYPE = "CDO Type";
public static final String Papyrus_TYPE = "Papyrus Type";
private String title;
private String type;
private int nbElementToCreate;
private Map<String, List<Long>> count = new HashMap<String, List<Long>>();
private List<Long> currentList = null;
private static final String NEWLINE = "\n";
private String createdElement;
public String getElementType() {
return this.createdElement;
}
public ExecutionTimeHelper(final String title, final String type, final int nbElementToCreate, String createdElement) {
this.title = title;
this.type = type;
this.nbElementToCreate = nbElementToCreate;
this.createdElement = createdElement;
}
public void startCounting(final String step) {
Assert.assertNull("The stop method has not been called", currentList);
currentList = new LinkedList<Long>();
count.put(step, currentList);
currentList.add(System.currentTimeMillis());
}
public void top() {
currentList.add(System.currentTimeMillis());
}
public void stop() {
currentList.add(System.currentTimeMillis());
currentList = null;
}
public String getType() {
return this.type;
}
/**
* @see java.lang.Object#toString()
*
* @return
*/
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("------");
builder.append(title);
builder.append("------");
builder.append(NEWLINE);
final Iterator<Entry<String, List<Long>>> iter = count.entrySet().iterator();
while (iter.hasNext()) {
final Entry<String, List<Long>> current = iter.next();
builder.append("# ");
builder.append(current.getKey());
builder.append(NEWLINE);
builder.append("## ");
for (int i = 0; i < current.getValue().size() - 1; i++) {
long diff = current.getValue().get(i + 1) - current.getValue().get(i);
builder.append(diff);
builder.append(NEWLINE);
}
builder.append(NEWLINE);
builder.append(NEWLINE);
}
return builder.toString();
}
public Map<String, List<Long>> getCount() {
return this.count;
}
public List<Long> getValuesForStep(final String step) {
return this.count.get(step);
}
/**
* @return
*/
public int getNbCreation() {
return this.nbElementToCreate;
}
}