Moved over first rbtree test from koka_bench and integrated Kraken via compiler wrapper script that calls the partial_evaluator / compiler and then emits a wrapper script that runs the resulting wasm via wasmtime.
This commit is contained in:
16
koka_bench/cpp/CMakeLists.txt
Normal file
16
koka_bench/cpp/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED YES)
|
||||
set(CMAKE_CXX_EXTENSIONS NO)
|
||||
|
||||
foreach (source IN ITEMS rbtree.cpp)
|
||||
get_filename_component(name "${source}" NAME_WE)
|
||||
set(name "cpp-${name}")
|
||||
|
||||
add_executable(${name} ${source})
|
||||
if(source MATCHES "binarytrees.cpp")
|
||||
target_link_libraries(${name} pthread)
|
||||
endif()
|
||||
|
||||
add_test(NAME ${name} COMMAND ${name})
|
||||
set_tests_properties(${name} PROPERTIES LABELS cpp)
|
||||
endforeach ()
|
||||
43
koka_bench/cpp/rbtree.cpp
Normal file
43
koka_bench/cpp/rbtree.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
// Using standard STL to test the red-black tree in C++
|
||||
// In glibc++ this uses <https://github.com/gcc-mirror/gcc/tree/master/libstdc++-v3/src/c++98/tree.cc>
|
||||
// With the LLVM libc++ this uses <https://github.com/llvm/llvm-project/blob/main/libcxx/include/__tree>
|
||||
// In glibc this uses eventually: <https://sourceware.org/git/?p=glibc.git;a=blob;f=misc/tsearch.c>
|
||||
// (Highly optimized in-place red-black tree using the low pointer bit to encode color information.)
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
using std::for_each;
|
||||
|
||||
typedef int nat;
|
||||
|
||||
struct nat_lt_fn {
|
||||
bool operator()(nat const & n1, nat const & n2) const { return n1 < n2; }
|
||||
};
|
||||
|
||||
typedef std::map<nat, bool, nat_lt_fn> map;
|
||||
|
||||
map mk_map(unsigned n) {
|
||||
map m;
|
||||
while (n > 0) {
|
||||
--n;
|
||||
m.insert(std::make_pair(nat(n), n%10 == 0));
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
nat fold(map const & m) {
|
||||
nat r(0);
|
||||
for_each(m.begin(), m.end(), [&](std::pair<nat, bool> const & p) { if (p.second) r = r + nat(1); });
|
||||
return r;
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
unsigned n = 4200000;
|
||||
if (argc == 2) {
|
||||
n = atoi(argv[1]);
|
||||
}
|
||||
map m = mk_map(n);
|
||||
std::cout << fold(m) << "\n";
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user