Skip to content

Commit 42bd45f

Browse files
authored
SedInstance[Task]: return the elapsed time of an/all instance/s in milliseconds.
2 parents 9b033d6 + abd491e commit 42bd45f

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

src/api/libopencor/sedinstance.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ class LIBOPENCOR_EXPORT SedInstance: public Logger
4747
* @brief Run all the tasks associated with this instance.
4848
*
4949
* Run all the tasks associated with this instance.
50+
*
51+
* @return The elapsed time in milliseconds.
5052
*/
5153

52-
void run();
54+
double run();
5355

5456
/**
5557
* @brief Return whether there are some tasks.

src/sed/sedinstance.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,23 @@ SedInstance::Impl::Impl(const SedDocumentPtr &pDocument, bool pCompiled)
7272
}
7373
}
7474

75-
void SedInstance::Impl::run()
75+
double SedInstance::Impl::run()
7676
{
7777
// Run all the tasks associated with this instance unless they have some issues.
7878

79+
auto res = 0.0;
80+
7981
for (const auto &task : mTasks) {
8082
if (!task->hasIssues()) {
81-
task->pimpl()->run();
83+
res += task->pimpl()->run();
8284

8385
if (task->hasIssues()) {
8486
addIssues(task);
8587
}
8688
}
8789
}
90+
91+
return res;
8892
}
8993

9094
bool SedInstance::Impl::hasTasks() const
@@ -131,9 +135,9 @@ const SedInstance::Impl *SedInstance::pimpl() const
131135
return reinterpret_cast<const Impl *>(Logger::pimpl());
132136
}
133137

134-
void SedInstance::run()
138+
double SedInstance::run()
135139
{
136-
pimpl()->run();
140+
return pimpl()->run();
137141
}
138142

139143
bool SedInstance::hasTasks() const

src/sed/sedinstance_p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SedInstance::Impl: public Logger::Impl
3131

3232
explicit Impl(const SedDocumentPtr &pDocument, bool pCompiled);
3333

34-
void run();
34+
double run();
3535

3636
bool hasTasks() const;
3737
size_t taskCount() const;

src/sed/sedinstancetask.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,12 @@ void SedInstanceTask::Impl::initialise()
174174
}
175175
}
176176

177-
void SedInstanceTask::Impl::run()
177+
double SedInstanceTask::Impl::run()
178178
{
179+
// Start our timer.
180+
181+
auto startTime = std::chrono::high_resolution_clock::now();
182+
179183
// (Re)initialise our model.
180184
// Note: reinitialise our model in case we are running our model multiple times.
181185

@@ -224,7 +228,7 @@ void SedInstanceTask::Impl::run()
224228
if (!mOdeSolver->pimpl()->solve(mVoi, std::min(voiStart + static_cast<double>(++voiCounter) * voiInterval, voiEnd))) {
225229
addIssues(mOdeSolver);
226230

227-
return;
231+
return 0.0;
228232
}
229233

230234
#ifndef __EMSCRIPTEN__
@@ -247,13 +251,17 @@ void SedInstanceTask::Impl::run()
247251
if ((mNlaSolver != nullptr) && mNlaSolver->hasIssues()) {
248252
addIssues(mNlaSolver);
249253

250-
return;
254+
return 0.0;
251255
}
252256
#endif
253257

254258
trackResults(++index);
255259
}
256260
}
261+
262+
// Stop our timer and return the elapsed time in milliseconds.
263+
264+
return std::chrono::duration<double, std::milli>(std::chrono::high_resolution_clock::now() - startTime).count();
257265
}
258266

259267
namespace {

src/sed/sedinstancetask_p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class SedInstanceTask::Impl: public Logger::Impl
6969
void trackResults(size_t pIndex);
7070

7171
void initialise();
72-
void run();
72+
double run();
7373

7474
Doubles voi() const;
7575
std::string voiName() const;

0 commit comments

Comments
 (0)