aboutsummaryrefslogtreecommitdiff
path: root/examples/Scheduler_example10_Benchmark/Scheduler_example10_Benchmark.ino
blob: 4c5b4e08c679ce2e67fc453c3f7a3ea35e2293bc (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
 * This is a test to benchmark TaskScheduler execution.
 * 
 * This test executes 1,000,000 cycles of a task with empty callback method
 * Compiled with different options, you can assess the impact of each on the size of the Task object
 * and the execution overhead of the main execution pass route.
 *
 * Sample execution times (in milliseconds per 1M iterations) are provided below.
 * The test board is Arduino UNO 16MHz processor.
 *
 
TaskScheduler 2.1.0:
No modifiers
Duration=19869

with SLEEP
Duration=20058

with status request:
Duration=20058

with time critical:
Duration=27289


TaskScheduler 1.9.0:
No modifiers
Duration=15656

with SLEEP
Duration=16285

with status request:
Duration=16600

with rollover fix:
Duration=18109


TaskScheduler 1.8.5:
Duration=15719

with SLEEP
Duration=16348

with status request:
Duration=18360

with rollover fix:
Duration=18423

 */


//#define _TASK_TIMECRITICAL     // Enable monitoring scheduling overruns
//#define _TASK_STATUS_REQUEST     // Compile with support for StatusRequest functionality - triggering tasks on status change events in addition to time only
//#define _TASK_WDT_IDS          // Compile with support for wdt control points and task ids
//#define _TASK_LTS_POINTER      // Compile with support for local task storage pointer
//#define _TASK_SLEEP_ON_IDLE_RUN
//#define _TASK_MICRO_RES
#include <TaskScheduler.h>

Scheduler ts;

// Callback methods prototypes
bool tOn(); void tOff();
void callback();

// Tasks
Task t(TASK_IMMEDIATE, 1000000, &callback, &ts, false, &tOn, &tOff);

unsigned long c1, c2;

bool tOn() {
  c1 = millis();
  c2 = 0;
  
  return true;
}

void tOff() {
  c2 = millis();
  Serial.println("done.");
  Serial.print("Tstart =");Serial.println(c1);
  Serial.print("Tfinish=");Serial.println(c2);
  Serial.print("Duration=");Serial.println(c2-c1);
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.print("Start...");

  t.enable();
}

void callback() {
  
}


void loop() {
  // put your main code here, to run repeatedly:
  ts.execute();
}