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
Name City Job
John Montreal Salesman
Kamel Lyon Researcher
Nathalie Montreal Translator
Bush Washington President
Tim Bray Vancouver Technologist
Daniel Montreal Professor
Peter Montreal Professor
Jack Montreal Professor
Nathalie Montreal Professor
@lemire
lemire / float.py
Created March 18, 2025 19:19
convert float to integers in Python
import struct
def float_to_scaled_int_double(f, p):
# Pack float as 64-bit double (IEEE 754 double precision)
packed = struct.pack('>d', f)
# Unpack as 64-bit unsigned integer
int_val = struct.unpack('>Q', packed)[0]
# Extract components (IEEE 754 double precision format):
@lemire
lemire / optimize.c
Created December 10, 2024 18:15
five functions in C that could be faster
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
int count(uint64_t x) {
int count = 0;
for(int k = 0; k < 64; k++) {
count += (x&1);
x >>= 1;
@lemire
lemire / find_all_constexpr.cpp
Created September 12, 2024 20:38
find_all_constexpr
#include <array>
#include <algorithm>
#include <string_view>
#include <utility>
#include <iostream>
#include <cstdint>
// Helper to get the first character of a string_view
@lemire
lemire / node_javascript.cc
Created September 8, 2024 21:44
node_javascript.cc generated by Yagiz's PR (Apple LLVM)
This file has been truncated, but you can view the full file.
#include "env-inl.h"
#include "node_builtins.h"
#include "node_external_reference.h"
#include "node_internals.h"
namespace node {
namespace builtins {
@lemire
lemire / gofun.go
Created July 12, 2024 00:18
slices.BinarySearch is slow?
package main
import (
"fmt"
"slices"
"testing"
)
var ok bool
import pandas as pd
import plot_likert
q1 = "pertinence"
q2 = "sentiment de\ncompétence"
q3 = "expérience"
myscale = ['Fortement en désaccord', 'Plutôt en désaccord',"Plutôt d'accord", "Fortement d'accord"]
precomputed_counts = pd.DataFrame(
{myscale[0]: {q1: 1, q2: 1, q3:1},
myscale[1]: {q1: 2, q2: 1, q3:1},
@lemire
lemire / adafuzz.cpp
Last active May 16, 2024 01:40
ada fuzz
#include <limits>
#include "fuzzer/FuzzedDataProvider.h" // see https://raw.githubusercontent.com/llvm/llvm-project/main/compiler-rt/include/fuzzer/FuzzedDataProvider.h
#include <memory>
#include <string>
// enables if needed
//#define ADA_LOGGING 1
#define ADA_DEVELOPMENT_CHECKS 1
#include "ada.cpp"
#include "ada.h"
@lemire
lemire / apple.cpp
Created April 28, 2024 21:23
some assembly benchmark
#include <algorithm>
#include <chrono>
#include <cstdint>
#include <iostream>
// The assembly is potentially unsafe because we read from the stack
// without checking. However, it appears to be good enough for our
// benchmarking purposes under LLVM.
@lemire
lemire / base64_runtime.cpp
Created April 2, 2024 18:37
base64 runtime functions (simdutf)
// on success: returns a non-negative integer indicating the size of the
// binary produced, it most be no larger than 2147483647 bytes.
// In case of error, a negativ value is returned:
// * -2 indicates an invalid character,
// * -1 indicates a single character remained,
// * -3 indicates a possible overflow (i.e., more than 2 GB output).