Skip to content

Instantly share code, notes, and snippets.

@ricejasonf
Created March 3, 2017 01:48
Show Gist options
  • Save ricejasonf/c9cfea01876b58d5778abcd934b14484 to your computer and use it in GitHub Desktop.
Save ricejasonf/c9cfea01876b58d5778abcd934b14484 to your computer and use it in GitHub Desktop.
Hana GroupBy Benchmark
cmake_minimum_required(VERSION 3.5)
add_definitions(-std=c++1z)
add_definitions(-DBOOST_HANA_CONFIG_ENABLE_STRING_UDL)
add_definitions(-ftemplate-backtrace-limit=0)
add_definitions(-Wall)
add_definitions(-Wextra)
include("/opt/metabench.cmake")
metabench_add_dataset(mpdef.list main.cpp "(0..20).step(1)"
NAME mpdef::list
ENV "{ use_empty_tuple: true }"
)
metabench_add_dataset(hana.tuple main.cpp "(0..20).step(1)"
NAME hana::tuple
ENV "{ use_empty_tuple: false }"
)
FROM ricejasonf/emscripten
WORKDIR /usr/local/src
RUN apt-get update \
&& apt-get install -yq ruby \
&& npm install http-server -g
# Metabench
RUN curl -o \
/opt/metabench.cmake \
https://raw.githubusercontent.com/ldionne/metabench/master/metabench.cmake
# Boost.Hana (clang c++1z workaround branch)
RUN git clone -b bugfix/constexpr_arrays https://github.com/ricejasonf/hana.git \
&& cp -r hana/include/* /usr/local/include \
&& rm -rf hana
# Nbdl
RUN git clone https://github.com/ricejasonf/nbdl.git \
&& cp -r nbdl/include/* /usr/local/include \
&& rm -rf nbdl
ARG BUILD_TYPE=Debug
ENV BUILD_TYPE ${BUILD_TYPE}
ARG PORT=8081
ENV PORT ${PORT}
EXPOSE ${PORT}
WORKDIR /opt/build
CMD cmake \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_CXX_FLAGS=" -stdlib=libc++" \
-DCMAKE_EXE_LINKER_FLAGS=" -lc++abi" \
/opt/src \
&& make index \
&& http-server -p $PORT
/*
* See the following for background information:
* http://stackoverflow.com/questions/42541148/how-do-i-speed-up-many-different-hanafilters-on-the-same-input-data
*/
#include <boost/hana.hpp>
#include <mpdef/list.hpp>
namespace hana = boost::hana;
<% if env[:use_empty_tuple] %>
constexpr auto make_tuple = mpdef::make_list;
<% else %>
constexpr auto make_tuple = hana::make_tuple;
<% end %>
struct source_equal_fn {
template<typename T, typename U>
constexpr auto operator()(T, U) const
-> hana::bool_<T::source == U::source>
{ return {}; }
};
struct source_less_than_fn {
template<typename T, typename U>
constexpr auto operator()(T, U) const
-> hana::bool_<T::source < U::source>
{ return {}; }
};
template <int I, int J, typename T> //dummy representation of a transition
struct transition {
static constexpr int source = I;
static constexpr int dest = J;
};
constexpr auto group_by_source = hana::compose(
hana::group.by(source_equal_fn{})
, hana::sort.by(source_less_than_fn{})
);
int main() {
#if defined(METABENCH)
//big test data
constexpr auto types = make_tuple(
<%= (10..n).map { |i|
(0..9).map { |j|
"transition<#{i + j}, 99, void>{}"
}.join(', ')
}.join(', ')
%>
);
//goal is to make a tuple of tuples, one for each states transitions
constexpr auto result = group_by_source(types);
#endif
}
.PHONY: image build
image:
docker pull ricejasonf/emscripten && docker build -t odin_quest .
build:
docker run --rm -p 8081:8081 -v ${shell pwd}:/opt/src:ro odin_quest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment