Skip to content

Commit

Permalink
Port profit-cli to use pre-allocated Image
Browse files Browse the repository at this point in the history
With the new facilities provided by the Model class, profit-cli now can
pre-allocate the Image holding the Model evaluation result, which both
increases the performance of the Model evaluation, and also allows
timing the time it takes to allocate (and zero-initialise) the Image
object.

Signed-off-by: Rodrigo Tobar <[email protected]>
  • Loading branch information
rtobar committed Jul 10, 2024
1 parent 20c7cbb commit ae10b62
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/apps/profit-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,18 @@ Image run(std::ostream &os, unsigned int iterations, Model &m, Point &offset) {
using std::chrono::system_clock;

/* This means that we evaluated the model once, but who cares */
Image result;
auto start = system_clock::now();
Image result {m.get_drawing_dimensions()};
auto end = system_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
os << "Allocated image in " << std::fixed << std::setprecision(3) << duration << " [ms]\n";

start = system_clock::now();
for(unsigned i=0; i!=iterations; i++) {
result = m.evaluate(offset);
m.evaluate(result, offset);
}
auto end = system_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
end = system_clock::now();
duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();

double dur_secs = (double)duration/1000;
double dur_per_iter = (double)duration/iterations;
Expand Down

0 comments on commit ae10b62

Please sign in to comment.