189 lines
3.4 KiB
Arduino
Raw Normal View History

2015-12-07 19:56:21 +01:00
//
2021-10-19 14:40:20 +02:00
// FILE: boolArrayDemo0.ino
2015-12-07 19:56:21 +01:00
// AUTHOR: Rob Tillaart
2021-10-19 14:40:20 +02:00
// VERSION: 0.2.4
2015-12-07 19:56:21 +01:00
// PURPOSE: demo performance reading boolean array
// DATE: 2015-12-06
// URL: https://forum.arduino.cc/index.php?topic=361167.0
//
2021-01-29 12:31:58 +01:00
2015-12-07 19:56:21 +01:00
#include "BoolArray.h"
2021-01-29 12:31:58 +01:00
2015-12-07 19:56:21 +01:00
BoolArray b;
uint32_t start;
uint32_t stop;
volatile long x = 0;
2020-11-27 11:10:47 +01:00
uint32_t duration1, duration2;
2021-01-29 12:31:58 +01:00
2015-12-07 19:56:21 +01:00
void setup()
{
Serial.begin(115200);
Serial.print("Start ");
Serial.println(__FILE__);
Serial.print("LIB VERSION:\t");
Serial.println(BOOLARRAY_LIB_VERSION);
2020-11-27 11:10:47 +01:00
int rv = b.begin(BOOLARRAY_MAXSIZE);
Serial.print("SIZE:\t");
Serial.println(b.size());
if (rv != BOOLARRAY_OK)
{
Serial.println("Boolarray alloc error");
while (1);
}
test0();
test1();
test2();
test3();
Serial.println("Done...");
}
2021-01-29 12:31:58 +01:00
2020-11-27 11:10:47 +01:00
void loop()
{
}
2021-01-29 12:31:58 +01:00
2020-11-27 11:10:47 +01:00
void test0()
{
Serial.println();
2021-10-19 14:40:20 +02:00
Serial.println("TEST SET(1)");
2020-11-27 11:10:47 +01:00
2015-12-07 19:56:21 +01:00
start = micros();
2020-11-27 11:10:47 +01:00
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
2015-12-07 19:56:21 +01:00
{
2020-11-27 11:10:47 +01:00
b.set(i, 1);
2015-12-07 19:56:21 +01:00
}
2020-11-27 11:10:47 +01:00
duration1 = micros() - start;
2015-12-07 19:56:21 +01:00
Serial.print("DURATION:\t");
2020-11-27 11:10:47 +01:00
Serial.println(duration1);
2015-12-07 19:56:21 +01:00
start = micros();
2020-11-27 11:10:47 +01:00
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
2015-12-07 19:56:21 +01:00
{
2020-11-27 11:10:47 +01:00
b.set(i, 1);
b.set(i, 1);
2015-12-07 19:56:21 +01:00
}
2020-11-27 11:10:47 +01:00
duration2 = micros() - start;
2015-12-07 19:56:21 +01:00
Serial.print("DURATION:\t");
2020-11-27 11:10:47 +01:00
Serial.println(duration2);
2021-10-19 14:40:20 +02:00
Serial.print("\t\t");
Serial.print(duration2 - duration1);
Serial.print("\t");
Serial.println((duration2 - duration1) / (1.0 * b.size()));
2020-11-27 11:10:47 +01:00
}
2021-01-29 12:31:58 +01:00
2020-11-27 11:10:47 +01:00
void test1()
{
Serial.println();
2021-10-19 14:40:20 +02:00
Serial.println("TEST SET(0)");
2015-12-07 19:56:21 +01:00
start = micros();
2020-11-27 11:10:47 +01:00
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
2015-12-07 19:56:21 +01:00
{
b.set(i, 0);
}
2020-11-27 11:10:47 +01:00
duration1 = micros() - start;
2015-12-07 19:56:21 +01:00
Serial.print("DURATION:\t");
2020-11-27 11:10:47 +01:00
Serial.println(duration1);
2015-12-07 19:56:21 +01:00
start = micros();
2020-11-27 11:10:47 +01:00
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
2015-12-07 19:56:21 +01:00
{
b.set(i, 0);
b.set(i, 0);
}
2020-11-27 11:10:47 +01:00
duration2 = micros() - start;
2015-12-07 19:56:21 +01:00
Serial.print("DURATION:\t");
2020-11-27 11:10:47 +01:00
Serial.println(duration2);
2021-10-19 14:40:20 +02:00
Serial.print("\t\t");
Serial.print(duration2 - duration1);
Serial.print("\t");
Serial.println((duration2 - duration1) / (1.0 * b.size()));
2020-11-27 11:10:47 +01:00
}
2015-12-07 19:56:21 +01:00
2021-01-29 12:31:58 +01:00
2020-11-27 11:10:47 +01:00
void test2()
{
Serial.println();
2021-10-19 14:40:20 +02:00
Serial.println("TEST GET(i)");
2020-11-27 11:10:47 +01:00
start = micros();
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
{
x += b.get(i);
}
duration1 = micros() - start;
Serial.print("DURATION:\t");
Serial.println(duration1);
start = micros();
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
{
x += b.get(i);
x += b.get(i);
}
duration2 = micros() - start;
Serial.print("DURATION:\t");
Serial.println(duration2);
2021-10-19 14:40:20 +02:00
Serial.print("\t\t");
Serial.print(duration2 - duration1);
Serial.print("\t");
Serial.println((duration2 - duration1) / (1.0 * b.size()));
2015-12-07 19:56:21 +01:00
}
2020-11-27 11:10:47 +01:00
void test3()
2015-12-07 19:56:21 +01:00
{
2020-11-27 11:10:47 +01:00
Serial.println();
start = micros();
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
{
b.set(i, 0);
}
2021-10-19 14:40:20 +02:00
duration1 = micros() - start;
Serial.print("TEST SET(0):\t");
2020-11-27 11:10:47 +01:00
Serial.println(duration1);
2021-10-19 14:40:20 +02:00
delay(10);
start = micros();
b.setAll(0);
duration2 = micros() - start;
Serial.print("TEST SETALL(0):\t");
Serial.println(duration2);
Serial.print("FACTOR:\t\t");
Serial.println(1.0 * duration1 / duration2);
Serial.println();
delay(10);
2020-11-27 11:10:47 +01:00
start = micros();
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
{
2021-10-19 14:40:20 +02:00
b.set(i, 1);
2020-11-27 11:10:47 +01:00
}
2021-10-19 14:40:20 +02:00
duration1 = micros() - start;
Serial.print("TEST SET(1):\t");
Serial.println(duration1);
delay(10);
start = micros();
b.setAll(1);
duration2 = micros() - start;
Serial.print("TEST SETALL(1):\t");
2020-11-27 11:10:47 +01:00
Serial.println(duration2);
2021-10-19 14:40:20 +02:00
Serial.print("FACTOR:\t\t");
Serial.println(1.0 * duration1 / duration2);
2015-12-07 19:56:21 +01:00
}
2020-11-27 11:10:47 +01:00
// -- END OF FILE --