Skip to content

Commit

Permalink
time measuring
Browse files Browse the repository at this point in the history
  • Loading branch information
Broseten committed May 23, 2017
1 parent d458a20 commit 1a1cb13
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import dk.ange.octave.type.OctaveDouble;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

import org.apache.commons.lang3.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -80,6 +82,23 @@ public void close() {
getOctave().close();
}

private static AtomicLong totalSettingTime;
private static AtomicLong totalSimulationTime;
private static AtomicLong totalParsingTime;

private static AtomicLong numOfSimulations;

static {
totalSettingTime = new AtomicLong();
totalSettingTime.set(0);
totalSimulationTime = new AtomicLong();
totalSimulationTime.set(0);
totalParsingTime = new AtomicLong();
totalParsingTime.set(0);
numOfSimulations = new AtomicLong();
numOfSimulations.set(0);
}

@Override
public Trajectory simulate(Point point, OdeSystem odeSystem, double timeLimit, PrecisionConfiguration precision) {
long settingStartTime = System.nanoTime();
Expand Down Expand Up @@ -115,7 +134,7 @@ public Trajectory simulate(Point point, OdeSystem odeSystem, double timeLimit, P
l_startTime = point.getTime();
l_endTime = timeLimit;
timeStep = precision.getTimeStep();
float[] l_times = new float[loadedData.length / octaveOdeSystem.dimension()];
l_times = new float[loadedData.length / octaveOdeSystem.dimension()];
float time = point.getTime();
for (int i = 0; i < l_times.length; i++) {
time += precision.getTimeStep();
Expand All @@ -125,11 +144,19 @@ public Trajectory simulate(Point point, OdeSystem odeSystem, double timeLimit, P

long timeTime = System.nanoTime() - timeStartTime;

// System.out.println("TIME");
// System.out.printf("Setting time: %.9f ms\n", settingTime / 1000000000.0);
// System.out.printf("Simulation time: %.9f ms\n", simulationTime / 1000000000.0);
totalSettingTime.addAndGet(settingTime);
totalSimulationTime.addAndGet(simulationTime);
totalParsingTime.addAndGet(parsingTime + timeTime);
numOfSimulations.addAndGet(1);

System.out.println("AVERAGE TIME");
System.out.printf("Setting time: %.9f ms\n", (totalSettingTime.get()/numOfSimulations.get()) / 1000000000.0);
System.out.printf("Simulation time: %.9f ms\n", (totalSimulationTime.get()/numOfSimulations.get()) / 1000000000.0);
// System.out.printf("Time time: %.9f ms\n", timeTime / 1000000000.0);
// System.out.printf("Parsing time: %.9f ms\n", parsingTime / 1000000000.0);
System.out.printf("Parsing time: %.9f ms\n", (totalParsingTime.get()/numOfSimulations.get()) / 1000000000.0);
System.out.println("Number of simulated trajectories: " + numOfSimulations.get());



if (paramValues.isEmpty()) {
return new ArrayTrajectory(data, l_times, point.getDimension());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.sybila.parasim.model.ode.OdeSystem;
import org.sybila.parasim.model.trajectory.*;

import java.util.concurrent.atomic.AtomicLong;


/**
* @author <a href="mailto:433392@fi.muni.cz">Vojtech Bruza</a>
Expand Down Expand Up @@ -48,8 +50,27 @@ public void close() {
float timeStep;


private static AtomicLong totalSettingTime;
private static AtomicLong totalSimulationTime;
private static AtomicLong totalParsingTime;

private static AtomicLong numOfSimulations;

static {
totalSettingTime = new AtomicLong();
totalSettingTime.set(0);
totalSimulationTime = new AtomicLong();
totalSimulationTime.set(0);
totalParsingTime = new AtomicLong();
totalParsingTime.set(0);
numOfSimulations = new AtomicLong();
numOfSimulations.set(0);
}


@Override
public Trajectory simulate(Point point, OdeSystem odeSystem, double timeLimit, PrecisionConfiguration precision) {
long settingStartTime = System.nanoTime();
Model model = odeSystem.getOriginalModel();

// System.out.println("PARAMETER VALUES: " + odeSystem.getAvailableParameters().keySet() +" VARIABLES: " + odeSystem.getVariables().keySet());
Expand Down Expand Up @@ -127,12 +148,16 @@ public Trajectory simulate(Point point, OdeSystem odeSystem, double timeLimit, P
}
}
solver.setAbsTol(maxAbsoluteError);
long settingTime = System.nanoTime() - settingStartTime;

//SIMULATION
long simulationStartTime = System.nanoTime();
try {
solution = solver.solve(interpreter, interpreter.getInitialValues(), l_timesDouble);
} catch (DerivativeException e) {
e.printStackTrace();
}
long simulationTime = System.nanoTime() - simulationStartTime;
//PARSING DATA TO TRAJECTORY

//help printing
Expand All @@ -151,6 +176,7 @@ public Trajectory simulate(Point point, OdeSystem odeSystem, double timeLimit, P
// }
// System.out.println("Start time: " + point.getTime() + " End Time: " + timeLimit);
// System.out.println("Number of iterations: " + numOfIterations);
long parsingStartTime = System.nanoTime();
int numberOfSteps = 0;
try{
numberOfSteps = solution.getRowCount();
Expand All @@ -163,6 +189,20 @@ public Trajectory simulate(Point point, OdeSystem odeSystem, double timeLimit, P
simulatedData[currentVariable + i * odeSystem.getVariables().size()] = (float) solution.getColumn(odeSystem.getVariable(currentVariable).getName()).getValue(i);
}
}
long parsingTime = System.nanoTime() - parsingStartTime;

totalSettingTime.addAndGet(settingTime);
totalSimulationTime.addAndGet(simulationTime);
totalParsingTime.addAndGet(parsingTime);
numOfSimulations.addAndGet(1);

System.out.println("AVERAGE TIME");
System.out.printf("Setting time: %.9f ms\n", (totalSettingTime.get()/numOfSimulations.get()) / 1000000000.0);
System.out.printf("Simulation time: %.9f ms\n", (totalSimulationTime.get()/numOfSimulations.get()) / 1000000000.0);
// System.out.printf("Time time: %.9f ms\n", timeTime / 1000000000.0);
System.out.printf("Parsing time: %.9f ms\n", (totalParsingTime.get()/numOfSimulations.get()) / 1000000000.0);
System.out.println("Number of simulated trajectories: " + numOfSimulations.get());

//OUTPUT TRAJECTORY
if (odeSystem.getAvailableParameters().isEmpty()) {
return new ArrayTrajectory(simulatedData, l_times, point.getDimension());
Expand Down

0 comments on commit 1a1cb13

Please sign in to comment.