Skip to content

Commit

Permalink
Parameterised the implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
reddragon committed Apr 29, 2012
1 parent 38fb2a2 commit b73bb15
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
31 changes: 23 additions & 8 deletions pma_tests/impl1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "../include/timer.hpp"
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

// WARNING: Do not change this.
#define VAL_C 2
Expand Down Expand Up @@ -480,16 +482,29 @@ void PackedMemoryArray<E>::delete_element_at(int index) {
exists[index] = 0;
}

int main() {
int main(int argc, char ** argv) {
PackedMemoryArray<int> pma(2);
srand(0);

Timer t;
t.start();
for(int i = 3; i < 10000000; i++) {
pma.insert_element(i);
int elems = atoi(argv[2]);
if (!strcmp(argv[1], "hammer")) {
Timer t;
t.start();
for(int i = 3; i < elems; i++) {
pma.insert_element(i);
}
double time_taken = t.stop();
std::cout << "Head Inserts of " << elems << " elements: " << time_taken/1000000.0 << " seconds " << std::endl;
}
double time_taken = t.stop();
std::cout << "Head Inserts: " << time_taken/1000000.0 << " seconds " << std::endl;
// std::cout << "Elements Moved: " << pma.total_moves << std::endl;
else if (!strcmp(argv[1], "random")) {
Timer t;
t.start();
for(int i = 3; i < elems; i++) {
pma.insert_element(rand()%(1<<30));
}
double time_taken = t.stop();
std::cout << "Random Inserts of " << elems << " elements: " << time_taken/1000000.0 << " seconds " << std::endl;
}
// std::cout << "Elements Moved: " << pma.total_moves << std::endl;
}

30 changes: 24 additions & 6 deletions pma_tests/impl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <stdlib.h>
#include <assert.h>
#include "../include/timer.hpp"
#include <cstring>

using namespace std;

Expand Down Expand Up @@ -385,12 +386,29 @@ is_sorted(Iter f, Iter l) {
}

int
main() {
main(int argc, char **argv) {

PMA p1;
for (int i = 0; i < 10000000; ++i) {
p1.insert(10001000 - i);
// v.insert(v.begin(), 100000 - i);
int elems = atoi(argv[2]);

Timer t;
if (!strcmp(argv[1], "hammer")) {
t.start();
for (int i = 0; i < elems; ++i) {
p1.insert(10001000 - i);
}
double ms = t.stop();
printf("Time taken for %d elements to be inserted at head: %lf\n", elems, ms/1000000.0);
printf("%llu moves to insert %d elements at head\n", nmoves, p1.size());
}
//printf("Time taken: %lf\n", ms/1000000.0);
printf("%llu moves to insert %d elements\n", nmoves, p1.size());
else if(!strcmp(argv[1], "random")) {
srand(0);
t.start();
for (int i = 0; i < elems; ++i) {
p1.insert(rand()%(1<<22));
}
double ms = t.stop();
printf("Time taken for %d elements to be inserted randomly: %lf\n", elems, ms/1000000.0);
printf("%llu moves to insert %d random elements\n", nmoves, p1.size());
}
}

0 comments on commit b73bb15

Please sign in to comment.