Skip to content

Commit

Permalink
Measure simulation time and startup time in the .h
Browse files Browse the repository at this point in the history
  • Loading branch information
imorlxs committed Oct 12, 2024
1 parent dec2ac9 commit ef73746
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
11 changes: 10 additions & 1 deletion demo/pyramidal_cell/src/pyramidal_cell.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,21 @@ inline void SaveNeuronMorphology(Simulation& sim) {

inline int Simulate(int argc, const char** argv) {
neuroscience::InitModule();

auto start = std::chrono::high_resolution_clock::now();
Simulation simulation(argc, argv);
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();

AddInitialNeuron({150, 150, 0});
CreateExtracellularSubstances(simulation.GetParam());

auto sim_start = std::chrono::high_resolution_clock::now();
simulation.GetScheduler()->Simulate(500);
auto sim_end = std::chrono::high_resolution_clock::now();
auto sim_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(sim_end - sim_start).count();
SaveNeuronMorphology(simulation);
std::cout << "Simulation completed successfully!" << std::endl;
std::cout << "Simulation completed successfully! Startup: " << elapsed << " ns" << " Run: " << sim_elapsed << " ns" << std::endl;
return 0;
}

Expand Down
11 changes: 10 additions & 1 deletion demo/soma_clustering/src/soma_clustering.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ inline int Simulate(int argc, const char** argv) {
// param->unschedule_default_operations = {"mechanical forces"};
};

auto start = std::chrono::high_resolution_clock::now();
Simulation simulation(argc, argv, set_param);
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();


// Define initial model
auto* param = simulation.GetParam();
Expand Down Expand Up @@ -99,7 +103,12 @@ inline int Simulate(int argc, const char** argv) {
"We recommend to run the simulation for roughly 6000 time "
"steps. Please change 'timesteps = ..'.");
}

auto sim_start = std::chrono::high_resolution_clock::now();
simulation.GetScheduler()->Simulate(timesteps);
auto sim_end = std::chrono::high_resolution_clock::now();
auto sim_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(sim_end - sim_start).count();


// Check if criterion is met
real_t spatial_range = 15;
Expand All @@ -109,7 +118,7 @@ inline int Simulate(int argc, const char** argv) {
} else {
std::cout << "<SomaClustering> Clustering criterion not met!" << std::endl;
}
std::cout << "Simulation completed successfully!\n";
std::cout << "Simulation completed successfully! Startup: " << elapsed << " ns" << " Run: " << sim_elapsed << " ns" << std::endl;
return 0;
}

Expand Down
10 changes: 9 additions & 1 deletion demo/tumor_concept/src/tumor_concept.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ inline int Simulate(int argc, const char** argv) {
param->max_bound = 100; // cube of 100*100*100
};

auto start = std::chrono::high_resolution_clock::now();
Simulation simulation(argc, argv, set_param);
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();

auto* ctxt = simulation.GetExecutionContext();
auto* param = simulation.GetParam();
auto* myrand = simulation.GetRandom();
Expand Down Expand Up @@ -137,9 +141,13 @@ inline int Simulate(int argc, const char** argv) {
ctxt->AddAgent(cell); // put the created cell in our cells structure

// Run simulation

auto sim_start = std::chrono::high_resolution_clock::now();
simulation.GetScheduler()->Simulate(500);
auto sim_end = std::chrono::high_resolution_clock::now();
auto sim_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(sim_end - sim_start).count();

std::cout << "Simulation completed successfully!" << std::endl;
std::cout << "Simulation completed successfully! Startup: " << elapsed << " ns" << " Run: " << sim_elapsed << " ns" << std::endl;
return 0;
}

Expand Down

0 comments on commit ef73746

Please sign in to comment.