Last active
August 23, 2023 07:00
-
-
Save ChristianAmannKT/55a690f825bb68701a3b87d2782b7ce6 to your computer and use it in GitHub Desktop.
ESP32 code to benchmark the arrays from https://github.com/K-Type-de/SubBitPackedArray/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include "bitpackedarray.h" | |
#include "subbitpackedarray.h" | |
#include "superbitpackedarray.h" | |
constexpr uint16_t num_states = 17; | |
constexpr std::size_t array_size = 100000; | |
constexpr std::size_t loop_size = 10000000; | |
void setup() | |
{ | |
Serial.begin(115200); | |
} | |
void loop() | |
{ | |
std::size_t before_time; | |
std::size_t after_time; | |
Serial.printf("Number of states: %lu\n", num_states); | |
Serial.printf("Number of values: %lu\n", array_size); | |
Serial.println(); | |
//BitPackedArray | |
{ | |
auto bit_array = new kt::BitPackedArray<num_states, array_size>{}; | |
Serial.printf("BitPackedArray Entries: %lu\n", bit_array->getEntrySize()); | |
Serial.printf("BitPackedArray Bytes used: %lu\n", bit_array->getByteSize()); | |
Serial.printf("Write/Read BitPackedArray %lu times...\n", loop_size); | |
before_time = millis(); | |
for(std::size_t i = 0; i < loop_size; ++i) | |
{ | |
bit_array->set(i % array_size, i % num_states); | |
bit_array->get(i % array_size); | |
} | |
after_time = millis(); | |
Serial.printf("Took %lu ms\n", after_time - before_time); | |
delete bit_array; | |
Serial.println(); | |
} | |
//SubBitPackedArray | |
{ | |
auto sub_bit_array = new kt::SubBitPackedArray<num_states, array_size>{}; | |
Serial.printf("SubBitPackedArray Entries: %lu\n", sub_bit_array->getEntrySize()); | |
Serial.printf("SubBitPackedArray Bytes used: %lu\n", sub_bit_array->getByteSize()); | |
Serial.printf("Write/Read SubBitPackedArray %lu times...\n", loop_size); | |
before_time = millis(); | |
for(std::size_t i = 0; i < loop_size; ++i) | |
{ | |
sub_bit_array->set(i % array_size, i % num_states); | |
sub_bit_array->get(i % array_size); | |
} | |
after_time = millis(); | |
Serial.printf("Took %lu ms\n", after_time - before_time); | |
delete sub_bit_array; | |
Serial.println(); | |
} | |
//SuperBitPackedArray | |
{ | |
auto super_bit_array = new kt::SuperBitPackedArray<num_states, array_size>{}; | |
Serial.printf("SuperBitPackedArray Entries: %lu\n", super_bit_array->getEntrySize()); | |
Serial.printf("SuperBitPackedArray Bytes used: %lu\n", super_bit_array->getByteSize()); | |
Serial.printf("Write/Read SuperBitPackedArray %lu times...\n", loop_size); | |
before_time = millis(); | |
for(std::size_t i = 0; i < loop_size; ++i) | |
{ | |
super_bit_array->set(i % array_size, i % num_states); | |
super_bit_array->get(i % array_size); | |
} | |
after_time = millis(); | |
Serial.printf("Took %lu ms\n", after_time - before_time); | |
delete super_bit_array; | |
} | |
delay(-1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment