Lolly 1.4.27
Loading...
Searching...
No Matches
timer.cpp
Go to the documentation of this file.
1
2/******************************************************************************
3 * MODULE : timer.cpp
4 * DESCRIPTION: timer related routines
5 * COPYRIGHT : (C) 2023 Darcy Shen
6 *******************************************************************************
7 * This software falls under the GNU general public license version 3 or later.
8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ******************************************************************************/
11
12#include "timer.hpp"
13#include "array.hpp"
14#include "hashmap.hpp"
15#include "iterator.hpp"
16#include "merge_sort.hpp"
17#include "tm_timer.hpp"
18
19namespace lolly {
20namespace system {
21
26
27/******************************************************************************
28 * Routines for benchmarking
29 ******************************************************************************/
30
31void
32timer_start (string task) {
33 // start timer for a given type of task
36}
37
38void
39timer_cumul (string task) {
40 // end timer for a given type of task, but don't reset timer
42 if (timing_level[task] == 0) {
44 timing_nr (task)++;
46 timing_last->reset (task);
47 }
48}
49
50void
51timer_reset (string task) {
52 // reset timer for a given type of task
53 timing_level->reset (task);
54 timing_nr->reset (task);
55 timing_cumul->reset (task);
56 timing_last->reset (task);
57}
58
59void
62 if (elapse_time < threshold) return;
63
65 ostream << "Task '" << task << "' took " << elapse_time << " ms";
66 if (nr > 1) ostream << " (" << nr << " invocations)";
67 ostream << LF;
68}
69
70static array<string>
74 while (it->busy ())
75 a << it->next ();
76 merge_sort (a);
77 return a;
78}
79
80void
82 // print timings for all types of tasks
84 int i, n= N (a);
85 for (i= 0; i < n; i++)
86 bench_print (ostream, a[i]);
87}
88
89} // namespace system
90} // namespace lolly
int N(array< T > a)
Get the length of the array.
Definition array.hpp:170
@ LF
Definition basic.hpp:287
The list class represents a linked list.
Definition list.hpp:48
iterator< T > iterate(hashmap< T, U > h)
Generates an iterator for a container of type hashmap<T, U>.
Definition iterator.ipp:166
void merge_sort(array< T > &a)
static array< string > collect(hashmap< string, uint32_t > h)
Definition timer.cpp:71
static hashmap< string, uint32_t > timing_level(0)
void timer_reset(string task)
Definition timer.cpp:51
void bench_print(tm_ostream &ostream, string task, uint32_t threshold)
Definition timer.cpp:60
static hashmap< string, uint32_t > timing_cumul(0)
static hashmap< string, uint32_t > timing_nr(0)
void timer_start(string task)
Definition timer.cpp:32
static hashmap< string, uint32_t > timing_last(0)
void timer_cumul(string task)
Definition timer.cpp:39
time_t texmacs_time()
Definition tm_timer.cpp:47