Skip to content

Instantly share code, notes, and snippets.

View Au-lit's full-sized avatar

Au-lit

View GitHub Profile

msvc results:

ns/op op/s err% total Random u32 to base 10. w/ /utf-8
2.71 369,270,304.57 1.4% 0.00 null, i.e. the rng perf
6.98 143,213,409.65 1.6% 0.00 jeaiii::to_text
9.63 103,842,159.92 0.4% 0.01 fmt::format_int
21.46 46,606,363.07 2.0% 0.01 std::to_string
21.56 46,372,782.63 1.1% 0.01 std::to_chars
54.56 18,329,649.17 1.0% 0.03 std::sprintf
576.23 1,735,415.94 0.8% 0.35 std::ostringstream

Please avoid

always (unless you have reeeally good reasons)

  • std::bind
  • std::function
  • std::type_info
  • std::vector<bool>
  • va_*
  • std::valarray
  • std::list
  • assert (instead use a thrower version / contracts)
@Au-lit
Au-lit / RandomValue.md
Last active April 16, 2021 23:15
A "simple" C++ function for random values...

A "simple" C++ function for random values : uniform_random_value()

To use uniform_random_value() include/paste the header random_value.hpp from this gist in your project; you can after simply write :

int randomInt = uniform_random_value(1, 100);
float randomFloat = uniform_random_value(1.0f, 100.0f);
double randomDouble = uniform_random_value(1.0, 100.0);

For the instance where you want a random boolean you can write :

@Au-lit
Au-lit / is_char.cpp
Last active April 15, 2021 22:35
A C++ is_char type trait.
// © Copyright 2021 Ollivier Roberge
#ifndef IS_CHAR_IMPL
#define IS_CHAR_IMPL
#include <type_traits>
template<typename T> struct is_char : std::false_type {};
template<> struct is_char<char> : std::true_type {};
template<> struct is_char<wchar_t> : std::true_type {};