Skip to content

Instantly share code, notes, and snippets.

View martinus's full-sized avatar
😎
warp! Help, I'm trapped in a time

Martin Leitner-Ankerl martinus

😎
warp! Help, I'm trapped in a time
View GitHub Profile
@martinus
martinus / .zshrc
Created August 17, 2021 08:18
helpful aliases for development
# cd to native directory and run the commands
run_in_venv() (
if [ -z "$VIRTUAL_ENV" ]; then
source ~/git/venv/bin/activate
fi
$@
)
# Sets CPU into a fixed state for the call, then resets it back.
bench() (
#include <cstddef>
#include <cstdint> // UINTPTR_MAX
#include <cstring> // memcpy
#include <memory> // allocator
#include <type_traits>
#include <utility>
#if _MSC_VER
# include <intrin.h> // required for CLZ builtin
#endif
// g++ -std=c++17 -O2 advent2016_day19.cpp -o advent2016_day19
#include <iostream>
#include <vector>
// Each elf points to the next in a circular linked list. We don't need to store an index number,
// because that is implicitly given by the location in the std::vector container where they all
// reside.
struct Elf {
Elf* next{};
@martinus
martinus / bulk_pool.h
Last active February 11, 2021 14:43
Bulk pool allocator
// Copyright (c) 2019 Martin Ankerl
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#pragma once
#include <cstddef>
#include <new>
#include <type_traits>
class UpToExecutor {
public:
UpToExecutor(int64_t begin, int64_t end, int64_t step)
: mBegin(begin)
, mEnd(end)
, mStep(step) {}
template <typename Op>
void operator()(Op op) {
#pragma once
#include <bitset>
#include <type_traits>
namespace util {
// Provides a type-safe bitset for enums
template <typename E>
class EnumFlags {

Warning, results might be unstable:

  • NDEBUG not defined, assert() macros are evaluated
  • CPU governor is '' but should be 'performance'

Recommendations

ns/op op/s err% ins/op cyc/op IPC total benchmark
@martinus
martinus / random_bool_benchmark.cpp
Last active October 15, 2019 05:42
fast random bool in C++
#include <algorithm>
#include <chrono>
#include <iostream>
#include <random>
#define LIKELY(x) __builtin_expect((x), 1)
#define UNLIKELY(x) __builtin_expect((x), 0)
#define NO_INLINE __attribute__((noinline))
// extremely fast random number generator that also produces very high quality random.
@martinus
martinus / .tmux.conf
Created September 25, 2019 11:09
Linux Configurations
# Automatically set window title
set-window-option -g automatic-rename on
set-option -g set-titles on
set-option -g history-limit 10000
# Enable mouse mode (tmux 2.1 and above)
setw -g mouse on
# remap prefix from 'C-b' to 'C-Space'
unbind C-b

Build with g++4-8, the oldest supported

CC=gcc-4.8 CXX=g++-4.8 CPPFLAGS=-D_GLIBCXX_USE_CXX11_ABI=0 ./configure --disable-wallet