Skip to content

Instantly share code, notes, and snippets.

View lemire's full-sized avatar
🚀
working hard and fast

Daniel Lemire lemire

🚀
working hard and fast
View GitHub Profile
template <int align> struct alignas(align) A {
volatile uint64_t count;
};
constexpr size_t iterations = 100'000'000;
void counter(volatile uint64_t *counterpt) {
for (size_t i = 0; i < iterations; i++) {
*counterpt = 3 * *counterpt * *counterpt + 1;
@lemire
lemire / Ascii.cs
Created August 29, 2023 16:51
Démo
using System;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
using System.Runtime.Intrinsics.Arm;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Ideally, we would want to implement something that looks like
// https://learn.microsoft.com/en-us/dotnet/api/system.text.asciiencoding?view=net-7.0
@lemire
lemire / timings.txt
Created May 24, 2023 23:56
Measurements from https://github.com/lemire/talks/tree/master/2023/performance/code (first column is timings, each row is a measure, other columns are performance counters)
52791.000000 164108.000000 353080.000000
43083.000000 134047.000000 342931.000000
42750.000000 132955.000000 342934.000000
42792.000000 133068.000000 342947.000000
42625.000000 132742.000000 342930.000000
42667.000000 132701.000000 342934.000000
42541.000000 132560.000000 342938.000000
42583.000000 132513.000000 342930.000000
42667.000000 132687.000000 342938.000000
42583.000000 132509.000000 342938.000000
@lemire
lemire / long_way.cpp
Created May 22, 2023 20:32
long way to do object/string to string
#include "simdjson.h"
#include <iostream>
using namespace simdjson; // optional
int main() {
padded_string json = R"( {"exports": {}} )"_padded;
ondemand::parser parser;
ondemand::document doc = parser.iterate(json);
ondemand::object obj;
auto err = doc.get_object().get(obj);
@lemire
lemire / script.js
Created May 8, 2023 23:33
roaring vs set
const Benchmark = require('benchmark');
const { TypedFastBitSet } = require('typedfastbitset');
const { RoaringBitmap32 } = require('roaring/RoaringBitmap32');
// Set utils
function union(set1, set2) {
return new Set([...set1, ...set2]);
}
function difference(set1, set2) {
@lemire
lemire / t.js
Created May 8, 2023 19:33
for each benchmark for TypeBitSet
/* performance benchmark */
/* This script expects node.js */
"use strict";
const { TypedFastBitSet, SparseTypedFastBitSet } = require("../lib");
const Benchmark = require("benchmark");
const os = require("os");
const smallgap = 3;
@lemire
lemire / fastpipeada.cpp
Created May 5, 2023 16:09
fast piping to ada...
#include <chrono>
#include <fstream>
#include <iostream>
#include <unistd.h>
#include <cstring>
#include <string_view>
#include <memory>
#include "ada.h"
struct line_iterator {
@lemire
lemire / simdutf_on_node.txt
Last active December 17, 2022 02:17
How one might include simdutf in node js
AVX-512 is a collection of instruction sets. The AVX-512 kernel in simdutf relies on VBMI2, one of the AVX-512
instruction sets. The simdutf library determines at runtime whether the processor supports VBMI2. If not, other (slower)
kernels are used, depending on the processor.
Not all compilers support the AVX-512 intrinsics that the simdutf library requires. Thus at compile-time, the library
checks for Visual Studio 2019 or better, or for the presence of the header 'avx512vbmi2intrin.h'.
At compile-time, it is thus assumed that if the compiler has access to 'avx512vbmi2intrin.h', then it can compile
the functions that are part of it and produce a VBMI2 code kernel. This should be a safe assumption.
@lemire
lemire / functionalcpp.cpp
Created October 27, 2022 13:35
Passing lambdas as values
#include <functional>
int g(int x, int y) {
auto lambda = [] <typename T>(std::function<T(T,T)> f, T x, T y) { return f(x,y); };
std::function<int(int,int)> f = [](int x, int y)->int {return x + y;};
return lambda(f, x,y);
}
/* auto-generated on 2022-10-06 13:43:02 +0000. Do not edit! */
// dofile: invoked with prepath=/home/lemire/CVS/github/simdutf/include, filename=simdutf.h
/* begin file include/simdutf.h */
#ifndef SIMDUTF_H
#define SIMDUTF_H
#include <cstring>
// dofile: invoked with prepath=/home/lemire/CVS/github/simdutf/include, filename=simdutf/compiler_check.h
/* begin file include/simdutf/compiler_check.h */
#ifndef SIMDUTF_COMPILER_CHECK_H