-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathticker.cpp
59 lines (41 loc) · 1.55 KB
/
ticker.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//------------------------------------------------------------------------------
#include "ticker.h"
//==============================================================================
bool Ticker::silent = false;
//==============================================================================
Ticker::Ticker()
{
ping_count = 0;
}
//------------------------------------------------------------------------------
Ticker::~Ticker()
{
}
//------------------------------------------------------------------------------
void Ticker::Start()
{
time_start = clock();
ping_count = 0; // Integral of pings received
}
//------------------------------------------------------------------------------
void Ticker::Tweet(string s)
{
if (silent) return; // Nothing to the console
if (time_start == clock_t(-1)) return; // Gotta call Start() first
ping_count++; // Update integral
clock_t t_delta = clock()-time_start; // Guess
if (t_delta==0) { // Too small to measure?
printf("--:--:--.--: %s %ld ~ 0 time \r",s.c_str(),ping_count);
return;
}
// Turn it into a 'per seconds' rate
long p_per_t = (CLOCKS_PER_SEC*ping_count)/t_delta;
printf("--:--:--.--: %s %ld @ %ld /s \r",s.c_str(),ping_count,p_per_t);
}
//------------------------------------------------------------------------------
void Ticker::VTab()
// Linux won't let me inline this
{
printf("\n\n");
}
//==============================================================================