Skip to content

Instantly share code, notes, and snippets.

View Ben1980's full-sized avatar

Benjamin Mahr Ben1980

View GitHub Profile
#include <iostream>
#include <vector>
void print(const std::vector<std::vector<int>> &vec) {
std::cout << "sizeof(int): " << sizeof(int) << '\n';
std::cout << "sizeof(std::vector<int>(10)): " << sizeof(std::vector<int>(10)) << '\n';
for(const auto & r : vec) {
std::cout << "Row address: " << &(r) << '\n';
for(const auto & c : r) {
std::cout << &(c) << ", ";
const size_t SIZE = 1000000;
void fill(int *arr) {
for(size_t i = 0; i < SIZE; ++i) {
arr[i] = i;
}
}
static void Heap(benchmark::State& state) {
int * test = new int[SIZE];
#include <iostream>
#include <vector>
void print(const std::vector<int> &vec) {
std::cout << "sizeof(int): " << sizeof(int) << ' ';
for(const auto & e : vec) {
std::cout << &(e) << ", ";
}
std::cout << std::endl;
pointer
_M_allocate(size_t __n)
{
typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Tr;
return __n != 0 ? _Tr::allocate(_M_impl, __n) : pointer(); //(3)
}
void
_M_create_storage(size_t __n)
{
template<typename T>
class Matrix {
static_assert(std::is_arithmetic<T>::value, "T must be numeric");
public:
Matrix(size_t rows, size_t columns, T *m)
: nbRows(rows), nbColumns(columns)
{
matrix.resize(nbRows);
for(size_t rowIndex = 0; rowIndex < nbRows; ++rowIndex) {
@Ben1980
Ben1980 / benchmark.cpp
Last active November 13, 2019 05:52
Container benchmark used on http://quick-bench.com
#include <vector>
#include <array>
#include <random>
#include <memory>
#include <algorithm>
const size_t COLUMNS = 500;
const size_t ROWS = 500;
static void TwoDimVector(benchmark::State& state) {
@Ben1980
Ben1980 / etokensign.cpp
Created July 30, 2019 14:29
etokensign command line tool by draketb https://stackoverflow.com/a/47894907/1541782
// etokensign.cpp : This file contains the 'main' function. Program execution begins and ends there.
// Source and thanks to draketb https://stackoverflow.com/a/47894907/1541782
#include <windows.h>
#include <cryptuiapi.h>
#include <iostream>
#include <string>
const std::wstring ETOKEN_BASE_CRYPT_PROV_NAME = L"eToken Base Cryptographic Provider";
class Bisection : public Iteration {
public:
Bisection(double epsilon, const std::function<double (double)> &f) : Iteration(epsilon), mf(f) {}
double solve(double a, double b) override {
resetNumberOfIterations();
checkAndFixAlgorithmCriteria(a, b);
fmt::print("Bisection -> [{:}, {:}]\n", a, b);
class LegendrePolynomial {
public:
LegendrePolynomial(double lowerBound, double upperBound, size_t numberOfIterations)
: mLowerBound(lowerBound), mUpperBound(upperBound), mNumberOfIterations(numberOfIterations), mWeight(numberOfIterations+1), mRoot(numberOfIterations+1) {
calculateWeightAndRoot();
}
const std::vector<double> & getWeight() const {
return mWeight;
}
std::vector<std::vector<double>> rombergIntegral(double a, double b, size_t n, const std::function<double (double)> &f) {
std::vector<std::vector<double>> romberg_integral(n, std::vector<double>(n));
//R(0,0) Start with trapezoidal integration with N = 1
romberg_integral.front().front() = trapezoidalIntegral(a, b, 1, f);
double h = b-a;
for(size_t step = 1; step < n; step++) {
h *= 0.5;