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
@lemire
lemire / avx512andzero.c
Last active August 25, 2018 14:53
It appears that any libcall is enough to get the registers dirty on AVX-512 capable hardware
/**
$ gcc -O2 -o fun fun.c -march=native -mno-avx512f && perf stat ./fun a b c 2>&1 |grep GHz && perf stat ./fun a b 2>&1 |grep GHz && perf stat ./fun a 2>&1 |grep GHz && perf stat ./fun 2>&1 |grep GHz
40,718,941 cycles # 3.167 GHz
40,719,004 cycles # 3.163 GHz
40,735,489 cycles # 2.796 GHz
40,707,631 cycles # 2.796 GHz
**/
#include <x86intrin.h>
#include <stdlib.h>
@lemire
lemire / badavx512.c
Created September 1, 2018 00:39
Why no throttling?
/***
$ cc -O3 -g3 -o badavx512 badavx512.c -march=native
$ perf stat ./badavx512
33686018
Performance counter stats for './badavx512':
1963.502013 task-clock (msec) # 1.000 CPUs utilized
3 context-switches # 0.002 K/sec
@lemire
lemire / funproblem.c
Created September 3, 2018 15:57
another mystery
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include "roaring.c"
int main() {
size_t bitmapcount = 2;
size_t size = 1000000;
struct timeval st, et;
@lemire
lemire / cachetest.cpp
Last active September 12, 2018 03:50
If you have M array accesses, how many cache misses can you have? What about 1.8 M cache misses...?
//
// $ g++ -O3 -o cachetest cachetest.cpp
// $ ./cachetest
// cycles = 349189333 (cycles per key 34.919) instructions = 190000063 (ins/key 19.000,ins/cycles 0.544) cache misses = 17385995 (misses per keys 1.739) branch misses = 6 (misses per keys 0.000)
//
// start helper header
// https://github.com/WojciechMula/toys/blob/master/000helpers/linux-perf-events.h
#ifdef __linux__
#include <asm/unistd.h> // for __NR_perf_event_open
.section __TEXT,__text,regular,pure_instructions
.macosx_version_min 10, 13
.section __TEXT,__literal16,16byte_literals
.p2align 4 ## -- Begin function _Z9timestampv
LCPI0_0:
.long 1127219200 ## 0x43300000
.long 1160773632 ## 0x45300000
.long 0 ## 0x0
.long 0 ## 0x0
LCPI0_1:
@lemire
lemire / nestedjson.py
Created November 23, 2018 19:02
Nested JSON generator (in Python)
import sys
depth = int(sys.argv[1])
s=""
for j in range(depth):
s+="["
s+="true"
for j in range(depth):
s+="]"
print(s)
rawdata = [["age","workclass","capital_loss"],["age","capital_gain","capital_loss"],["age","workclass","capital_loss","x"],["age","capital_gain","capital_loss","x"],["workclass","hours_per_week","native_country"],["age","capital_loss","native_country"],["workclass","hours_per_week","native_country","x"],["age","capital_loss","native_country","x"],["age","capital_loss","x"],["age","capital_gain","native_country"],["age","workclass","capital_gain"],["age","workclass","capital_gain","x"],["age","capital_gain","native_country","x"],["age","capital_gain","x"]]
print("how many sets", len(rawdata))
sdata = map(set,rawdata)
#print(len(sdata))
total = len(sdata)
allkeys = reduce(lambda x,y :x.union(y),sdata)
print("how many attributes ", len(allkeys))
l = set()
d = []
/***
result:
152ca78d
027c6003
cb07bbf3
f98befee
1cd777e3
a4e29590
661e4b6d
@lemire
lemire / Basic.java
Last active February 25, 2019 22:13
Some RoaringBitmap issue
import org.roaringbitmap.*;
import java.io.*;
import java.util.*;
public class Basic {
public static void main(String[] args) throws IOException {
DataInputStream in;
in = new DataInputStream(new FileInputStream(args[0]));
import org.roaringbitmap.RoaringBitmap;
import org.roaringbitmap.buffer.*;
import java.io.*;
import java.nio.*;
public class Issue319 {