2015-12-06 14:50:00 -05:00
|
|
|
//
|
|
|
|
// FILE: bitArrayDemo2.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
2021-10-19 10:11:27 -04:00
|
|
|
// VERSION: 0.1.3
|
2015-12-06 14:50:00 -05:00
|
|
|
// PURPOSE: demo performance reading boolean array
|
|
|
|
// DATE: 2015-12-06
|
2021-10-19 10:11:27 -04:00
|
|
|
// URL: https://github.com/RobTillaart/BitArray
|
2015-12-06 14:50:00 -05:00
|
|
|
// URL: https://forum.arduino.cc/index.php?topic=361167.0
|
|
|
|
//
|
2021-10-19 10:11:27 -04:00
|
|
|
|
2015-12-06 14:50:00 -05:00
|
|
|
|
|
|
|
#include "BitArray.h"
|
|
|
|
|
|
|
|
BitArray b;
|
|
|
|
|
|
|
|
uint32_t start;
|
|
|
|
uint32_t stop;
|
2017-07-16 07:39:43 -04:00
|
|
|
volatile int32_t x = 0;
|
2015-12-06 14:50:00 -05:00
|
|
|
|
2021-10-19 10:11:27 -04:00
|
|
|
|
2015-12-06 14:50:00 -05:00
|
|
|
void setup()
|
|
|
|
{
|
2015-12-09 16:51:16 -05:00
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.print("Start ");
|
|
|
|
Serial.println(__FILE__);
|
|
|
|
Serial.print("LIB VERSION:\t");
|
|
|
|
Serial.println(BITARRAY_LIB_VERSION);
|
2015-12-06 14:50:00 -05:00
|
|
|
|
2015-12-09 16:51:16 -05:00
|
|
|
test(1, 10000);
|
|
|
|
test(2, 5000);
|
|
|
|
test(3, 3333);
|
|
|
|
test(4, 2500);
|
2015-12-09 15:59:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void test(uint8_t bits, uint16_t cnt)
|
|
|
|
{
|
2015-12-09 16:51:16 -05:00
|
|
|
b.begin(bits, cnt);
|
|
|
|
Serial.print("CAPACITY:\t");
|
|
|
|
Serial.println(b.capacity());
|
|
|
|
Serial.print(" MEMORY:\t");
|
|
|
|
Serial.println(b.memory());
|
|
|
|
Serial.print(" BITS:\t");
|
|
|
|
Serial.println(b.bits());
|
|
|
|
Serial.print("SEGMENTS:\t");
|
|
|
|
Serial.println(b.segments());
|
|
|
|
delay(100);
|
2015-12-09 15:59:28 -05:00
|
|
|
|
2015-12-09 16:51:16 -05:00
|
|
|
start = micros();
|
2017-07-16 07:39:43 -04:00
|
|
|
for (uint16_t i = 0; i < cnt; i++)
|
2015-12-09 16:51:16 -05:00
|
|
|
{
|
|
|
|
x += b.get(i);
|
|
|
|
}
|
|
|
|
stop = micros();
|
|
|
|
Serial.print("DURATION:\t");
|
|
|
|
Serial.println(stop - start);
|
|
|
|
delay(100);
|
2015-12-06 14:50:00 -05:00
|
|
|
|
2015-12-09 16:51:16 -05:00
|
|
|
start = micros();
|
2017-07-16 07:39:43 -04:00
|
|
|
for (uint16_t i = 0; i < cnt; i++)
|
2015-12-09 16:51:16 -05:00
|
|
|
{
|
|
|
|
x += b.get(i);
|
|
|
|
x += b.get(i);
|
|
|
|
}
|
|
|
|
stop = micros();
|
|
|
|
Serial.print("DURATION:\t");
|
|
|
|
Serial.println(stop - start);
|
|
|
|
Serial.print(" X:\t");
|
|
|
|
Serial.println(x);
|
|
|
|
delay(100);
|
2015-12-06 14:50:00 -05:00
|
|
|
|
2015-12-09 16:51:16 -05:00
|
|
|
start = micros();
|
2017-07-16 07:39:43 -04:00
|
|
|
for (uint16_t i = 0; i < cnt; i++)
|
2015-12-09 16:51:16 -05:00
|
|
|
{
|
|
|
|
b.set(i, 0);
|
|
|
|
}
|
|
|
|
stop = micros();
|
|
|
|
Serial.print("DURATION:\t");
|
|
|
|
Serial.println(stop - start);
|
|
|
|
delay(100);
|
2015-12-06 14:50:00 -05:00
|
|
|
|
2015-12-09 16:51:16 -05:00
|
|
|
start = micros();
|
2017-07-16 07:39:43 -04:00
|
|
|
for (uint16_t i = 0; i < cnt; i++)
|
2015-12-09 16:51:16 -05:00
|
|
|
{
|
|
|
|
b.set(i, 0);
|
|
|
|
b.set(i, 0);
|
|
|
|
}
|
|
|
|
stop = micros();
|
|
|
|
Serial.print("DURATION:\t");
|
|
|
|
Serial.println(stop - start);
|
|
|
|
delay(100);
|
2015-12-06 14:50:00 -05:00
|
|
|
|
2015-12-09 16:51:16 -05:00
|
|
|
start = micros();
|
|
|
|
b.clear();
|
|
|
|
stop = micros();
|
|
|
|
Serial.print("DURATION:\t");
|
|
|
|
Serial.println(stop - start);
|
|
|
|
delay(100);
|
|
|
|
|
|
|
|
Serial.println("Done...");
|
2015-12-06 14:50:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
2015-12-09 15:59:28 -05:00
|
|
|
}
|