Skip to content

Instantly share code, notes, and snippets.

@CodeMouse92
Created June 21, 2017 04:14
Show Gist options
  • Save CodeMouse92/839657990cc73818c4b3a1a4f9c1eba0 to your computer and use it in GitHub Desktop.
Save CodeMouse92/839657990cc73818c4b3a1a4f9c1eba0 to your computer and use it in GitHub Desktop.
Goldilocks Benchmark Demo
#include "pawlib/iochannel.hpp"
#include "pawlib/goldilocks.hpp"
using namespace pawlib;
using namespace pawlib::ioformat;
void bubblesort(int* arr, int len)
{
int temp;
bool swap;
do
{
swap = false;
for (int i = 0; i<(len-1); ++i)
{
if(arr[i] > arr[i+1])
{
temp = arr[i];
arr[i] = arr[i+1];
arr[i+1] = temp;
swap = true;
}
}
}
while(swap);
}
void selectionsort(int* arr, int len)
{
int s, mi, mv;
for (s=0; s<(len+1); ++s)
{
mi = s;
mv = arr[s];
for(int i = s+1; i<len; ++i)
{
if(arr[i] < mv)
{
mv = arr[i];
mi = i;
}
}
arr[mi] = arr[s];
arr[s] = mv;
}
}
class TestBubbleSort : public Test
{
public:
TestBubbleSort(){}
testdoc_t get_title()
{
return "Bubble Sort";
}
testdoc_t get_docs()
{
return "Runs a bubble sort.";
}
bool run()
{
int arr[10] = {42, 57, 96, 21, 66, 17, 10, 97, 43, 86};
bubblesort(arr, 10);
}
~TestBubbleSort(){}
};
class TestSelectionSort : public Test
{
public:
TestSelectionSort(){}
testdoc_t get_title()
{
return "Selection Sort";
}
testdoc_t get_docs()
{
return "Runs a selection sort.";
}
bool run()
{
int arr[10] = {42, 57, 96, 21, 66, 17, 10, 97, 43, 86};
selectionsort(arr, 10);
}
~TestSelectionSort(){}
};
int main()
{
TestManager* testmanager = new TestManager();
testmanager->register_test("BubbleSort", new TestBubbleSort);
testmanager->register_test("SelectionSort", new TestSelectionSort);
testmanager->run_compare("BubbleSort", "SelectionSort", 1000);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment