springderek
Member
Out of curiosity i was trying to run my own version of the array vs linked list benchmark to see how it fairs on the teensy, but i get the following compile error in Arduino 1.05
here's my code
Code:
vecotrVsLinkedList.cpp.o: In function `emplace<int>':
/Applications/Arduino105.app/Contents/Resources/Java/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/include/c++/4.7.2/bits/list.tcc:92: undefined reference to `std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*)'
vecotrVsLinkedList.cpp.o: In function `std::list<int, std::allocator<int> >::_M_erase(std::_List_iterator<int>)':
/Applications/Arduino105.app/Contents/Resources/Java/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/include/c++/4.7.2/bits/stl_list.h:1542: undefined reference to `std::__detail::_List_node_base::_M_unhook()'
collect2: error: ld returned 1 exit status
here's my code
Code:
#include <list>
#include <vector>
int n = 10;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) { }
}
void loop() {
delay(200);
myTest(n);
n++;
}
void myTest(int n) {
Serial.print("\nlinked list size:");
Serial.print(n);
unsigned long execTime = micros();
testList(n);
execTime = execTime - micros();
Serial.print(" test took: ");
Serial.print(execTime);
Serial.println(" micros");
Serial.print("\nvector list size:");
Serial.print(n);
execTime = micros();
testVector(n);
execTime = execTime - micros();
Serial.print(" test took: ");
Serial.print(execTime);
Serial.println(" micros");
}
void testList(int n) {
//create random number generator with pi seed
srand(314159265359);
//create datastructure
std::list<int> l;
//insert n things
int m = n;
int i = 0;
while (n) {
//insert in random position
int insertIndex = rand() % i++;
auto it = l.begin();
for(int j=0; i<insertIndex; j++) {
++it;
}
l.insert(it, (rand() % 1000000000));
--n;
}
//dequeue m things
while (m) {
int eraseIndex = (rand() % m);
auto it = l.begin();
for(int j=0; i<eraseIndex; j++) {
++it;
}
l.erase(it);
--m;
}
}
void testVector(int n) {
//create random number generator with pi seed
srand(314159265359);
//create datastructure
std::vector<int> v;
//insert n things
int m = n;
int i = 0;
while (n) {
//insert in random position
int insertIndex = rand() % i++;
auto it = v.begin();
for(int j=0; j<insertIndex; j++) {
++it;
}
v.insert(it, (rand() % 1000000000));
--n;
}
//dequeue m things
while (m) {
int eraseIndex = (rand() % m);
auto it = v.begin();
for(int j=0; i<eraseIndex; j++) {
++it;
}
v.erase(it);
--m;
}
}