Scheduler_example10_Benchmark.ino 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * This is a test to benchmark TaskScheduler execution.
  3. *
  4. * This test executes 1,000,000 cycles of a task with empty callback method
  5. * Compiled with different options, you can assess the impact of each on the size of the Task object
  6. * and the execution overhead of the main execution pass route.
  7. *
  8. * Sample execution times (in milliseconds per 1M iterations) are provided below.
  9. * The test board is Arduino UNO 16MHz processor.
  10. *
  11. TaskScheduler 2.1.0:
  12. No modifiers
  13. Duration=19869
  14. with SLEEP
  15. Duration=20058
  16. with status request:
  17. Duration=20058
  18. with time critical:
  19. Duration=27289
  20. TaskScheduler 1.9.0:
  21. No modifiers
  22. Duration=15656
  23. with SLEEP
  24. Duration=16285
  25. with status request:
  26. Duration=16600
  27. with rollover fix:
  28. Duration=18109
  29. TaskScheduler 1.8.5:
  30. Duration=15719
  31. with SLEEP
  32. Duration=16348
  33. with status request:
  34. Duration=18360
  35. with rollover fix:
  36. Duration=18423
  37. */
  38. //#define _TASK_TIMECRITICAL // Enable monitoring scheduling overruns
  39. //#define _TASK_STATUS_REQUEST // Compile with support for StatusRequest functionality - triggering tasks on status change events in addition to time only
  40. //#define _TASK_WDT_IDS // Compile with support for wdt control points and task ids
  41. //#define _TASK_LTS_POINTER // Compile with support for local task storage pointer
  42. //#define _TASK_SLEEP_ON_IDLE_RUN
  43. //#define _TASK_MICRO_RES
  44. #include <TaskScheduler.h>
  45. Scheduler ts;
  46. // Callback methods prototypes
  47. bool tOn(); void tOff();
  48. void callback();
  49. // Tasks
  50. Task t(TASK_IMMEDIATE, 1000000, &callback, &ts, false, &tOn, &tOff);
  51. unsigned long c1, c2;
  52. bool tOn() {
  53. c1 = millis();
  54. c2 = 0;
  55. return true;
  56. }
  57. void tOff() {
  58. c2 = millis();
  59. Serial.println("done.");
  60. Serial.print("Tstart =");Serial.println(c1);
  61. Serial.print("Tfinish=");Serial.println(c2);
  62. Serial.print("Duration=");Serial.println(c2-c1);
  63. }
  64. void setup() {
  65. // put your setup code here, to run once:
  66. Serial.begin(115200);
  67. Serial.print("Start...");
  68. t.enable();
  69. }
  70. void callback() {
  71. }
  72. void loop() {
  73. // put your main code here, to run repeatedly:
  74. ts.execute();
  75. }