-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathBenchmarkAceTime.cpp
74 lines (61 loc) · 1.89 KB
/
BenchmarkAceTime.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Test the performance of the AceTime library.
*/
#include <stdio.h>
#include <string>
#include <vector> // vector<>
#include <Arduino.h>
#include <AceTime.h>
#include "BenchmarkAceTime.h"
using namespace std;
using namespace ace_time;
static ExtendedZoneProcessorCache<1> zoneProcesorCache;
static ExtendedZoneManager zoneManager(
zonedbx::kZoneAndLinkRegistrySize,
zonedbx::kZoneAndLinkRegistry,
zoneProcesorCache
);
static volatile uint32_t epochSeconds;
static int processZone(const TimeZone& tz, int startYear, int untilYear) {
//tz.printTo(SERIAL_PORT_MONITOR);
//SERIAL_PORT_MONITOR.println();
int count = 0;
for (int16_t y = startYear; y < untilYear; y++) {
for (uint8_t m = 1; m <= 12; m++) {
for (uint8_t d = 1; d <= 28; d++) {
count++;
ZonedDateTime zdt = ZonedDateTime::forComponents(
y, m, d, 1, 2, 3, tz);
epochSeconds = zdt.toEpochSeconds();
}
}
}
return count;
}
void benchmarkAceTime(
const vector<string>& zones,
int startYear,
int untilYear) {
printf("benchmarkAceTime: start\n");
unsigned long startMillis = millis();
int totalCount = 0;
for (string zoneName : zones) {
TimeZone tz = zoneManager.createForZoneName(zoneName.c_str());
int count = processZone(tz, startYear, untilYear);
totalCount += count;
}
unsigned long elapsedMillis = millis() - startMillis;
printf("benchmarkAceTime: zones=%d\n", (int) zones.size());
printf("benchmarkAceTime: count=%d\n", totalCount);
printf("benchmarkAceTime: elapsedMillis %ld\n", elapsedMillis);
double duration = (totalCount == 0)
? 0.0
: (double) elapsedMillis * 1000 / (double) totalCount;
printf("benchmarkAceTime: micros/iter %.3f\n", duration);
/*
for (int16_t index = 0; index < zonedbx::kZoneAndLinkRegistrySize; index++) {
TimeZone tz = zoneManager.createForIndex(index);
processZone(tz);
}
*/
}