Skip to content

Commit 31bf136

Browse files
committed
Benchmark R3 KOKESortV2 Support, New Visualizer, extern C for parts, Visualizer new fit functions with R^2 calculation
1 parent a3d61f2 commit 31bf136

File tree

17 files changed

+386
-48
lines changed

17 files changed

+386
-48
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,6 @@ mutated/
7171
**/state.json
7272
**/voters.json
7373

74-
**/futOutput*
74+
**/futOutput*
75+
76+
**/benchmark_results*

src/CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,12 @@ include(CPack)
193193

194194
set_target_properties(KOKESort PROPERTIES POSITION_INDEPENDENT_CODE ON)
195195

196-
if(WIN32 AND NOT PYBINDWRAPPER)
197-
target_compile_definitions(KOKESort PRIVATE KOKESORT_EXPORTS)
196+
if(PYBINDWRAPPER)
197+
message("KOKESORT_STATIC Defined")
198+
target_compile_definitions(KOKESort PRIVATE KOKESORT_STATIC)
198199
else()
199-
message(INFO "KOKESORT_STATIC Defined")
200-
target_compile_definitions(KOKESort PRIVATE KOKESORT_STATIC)
200+
message("KOKESORT_EXPORTS Defined")
201+
target_compile_definitions(KOKESort PRIVATE KOKESORT_EXPORTS)
201202
endif()
202203

203204
#target_compile_definitions(KOKESort PRIVATE KOKESORT_IMPORTS)

src/Global.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ extern "C" { /* C++ name mangling */
7575
#ifdef WINDOWS
7676
#if defined(KOKESORT_STATIC)
7777
#define KOKESORT_API
78-
#elif defined(KOKESORT_IMPORTS)
79-
#define KOKESORT_API __declspec(dllimport)
78+
//#elif defined(KOKESORT_IMPORTS)
79+
// #define KOKESORT_API __declspec(dllimport)
8080
#elif defined(KOKESORT_EXPORTS)
8181
#define KOKESORT_API __declspec(dllexport)
8282
#else
83-
#define KOKESORT_API
83+
#define KOKESORT_API __declspec(dllimport)
8484
#endif
8585
#else
8686
#define KOKESORT_API

src/benchmarkr3/config.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
typedef int GenerateValueType;
4+
5+
const int MaxValue = 10000000;
6+
7+
//For KOKESortV2
8+
const int SpaceCount = 100;

src/benchmarkr3/cwrappersys.hpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
22
#include <functional>
3-
4-
using CompareFunction = int(*)(const void*, const void*);
5-
using CSortFunction = void(*)(void* arr, size_t size, size_t elemSize, CompareFunction cmp);
3+
#include <sort.h>
4+
#include <KOKESortV2.h>
5+
#include <config.hpp>
66

77
template<typename T>
88
int default_compare(const void* a, const void* b) {
@@ -20,7 +20,7 @@ int default_compare(const void* a, const void* b) {
2020
}
2121

2222
template<typename T>
23-
std::function<void(std::vector<T>&)> wrap_c_sort(CSortFunction sorter) {
23+
std::function<void(std::vector<T>&)> wrap_c_sort(SortFunction sorter) {
2424
return [sorter](std::vector<T>& vec)
2525
{
2626
if (vec.empty())
@@ -29,4 +29,24 @@ std::function<void(std::vector<T>&)> wrap_c_sort(CSortFunction sorter) {
2929
}
3030
sorter(static_cast<void*>(vec.data()), vec.size(), sizeof(T), default_compare<T>);
3131
};
32+
}
33+
34+
GenerateValueType Divider = MaxValue / SpaceCount;
35+
36+
size_t indexer(const void *valptr)
37+
{
38+
const GenerateValueType val1 = *(const GenerateValueType *)valptr;
39+
return val1 / Divider;
40+
}
41+
42+
template<typename T>
43+
std::function<void(std::vector<T>&)> wrap_c_sort_for_KOKESortV2(SortFunction sorter) {
44+
return [sorter](std::vector<T>& vec)
45+
{
46+
if (vec.empty())
47+
{
48+
return;
49+
}
50+
SortV2(static_cast<void*>(vec.data()), vec.size(), sizeof(T), SpaceCount, indexer, default_compare<T>, sorter);
51+
};
3252
}

src/benchmarkr3/main.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include "sortsys.hpp"
21
#include <iostream>
32
#include <fstream>
43
#include <chrono>
@@ -7,6 +6,7 @@
76

87
#include <sortsys.hpp>
98
#include <cwrappersys.hpp>
9+
#include <config.hpp>
1010

1111
using json = nlohmann::json;
1212

@@ -53,21 +53,6 @@ void initialize_csv(const std::string &filename)
5353
std::cerr << "Error: Could not create file!" << std::endl;
5454
}
5555
}
56-
57-
typedef int GenerateValueType;
58-
59-
const int MaxValue = 10000000;
60-
61-
const int SpaceCount = 100;
62-
63-
GenerateValueType Divider = MaxValue / SpaceCount;
64-
65-
size_t indexer(const void *valptr)
66-
{
67-
const GenerateValueType val1 = *(const GenerateValueType *)valptr;
68-
return val1 / Divider;
69-
}
70-
7156
template <typename T>
7257
std::vector<T> random_vector(size_t size, T min, T max)
7358
{

src/benchmarkr3/sortsys.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ using SorterFunction = std::function<void(std::vector<int>&)>;
1515
#define SORT_FN(name, func) { name, [](SORT_VEC) { func(v); } }
1616
#define SORT_CPP(name, sorter) SORT_FN(name, cppsort::sorter{})
1717
#define SORT_C(name, cfunc) SORT_FN(name, wrap_c_sort<int>(cfunc))
18+
#define SORT_C_KOKESortV2(name, cfunc) SORT_FN(name, wrap_c_sort_for_KOKESortV2<int>(cfunc))
1819

1920
inline std::unordered_map<std::string, SorterFunction> get_sorters() {
2021
return
@@ -27,6 +28,7 @@ inline std::unordered_map<std::string, SorterFunction> get_sorters() {
2728
SORT_C("c_quick", quickSort),
2829
SORT_C("c_selection", selectionSort),
2930
SORT_C("c_kokev1", SortV1Self),
31+
SORT_C_KOKESortV2("c_kokev2_quick", quickSort),
3032
SORT_CPP("counting", counting_sorter),
3133
SORT_CPP("drop_merge", drop_merge_sorter),
3234
SORT_CPP("heap", heap_sorter),

src/benchmarkr3/test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"c_quick",
99
"c_selection",
1010
"c_kokev1",
11+
"c_kokev2_quick",
1112
"counting",
1213
"drop_merge",
1314
"heap",

src/parts/bubblesort.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33

44
#include <sort.h>
55

6+
#ifdef __cplusplus
7+
extern "C" { /* C++ name mangling */
8+
#endif
9+
610
KOKESORT_API void bubbleSort(void *arr, size_t n, size_t elementSize, CompareFunction cmp);
711

12+
#ifdef __cplusplus
13+
};
14+
#endif
15+
816
#endif

src/parts/heapsort.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33

44
#include <sort.h>
55

6+
#ifdef __cplusplus
7+
extern "C" { /* C++ name mangling */
8+
#endif
9+
610
KOKESORT_API void heapSort(void *arr, size_t n, size_t elementSize, CompareFunction cmp);
711

12+
#ifdef __cplusplus
13+
};
14+
#endif
15+
816
#endif

0 commit comments

Comments
 (0)