#include <stdlib.h>
void * jmalloc(size_t size) {
return malloc(size);
}
void jfree(void * ptr) {
free(ptr);
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Before | |
--------------------------------------------------------------------------------------------------------------------------- | |
Benchmark Time CPU Iterations | |
--------------------------------------------------------------------------------------------------------------------------- | |
BM_HpackEncoderInitDestroy 198 ns 198 ns 3535074 | |
BM_HpackEncoderEncodeDeadline 129 ns 129 ns 5219422 framing_bytes/iter:9 header_bytes/iter:6 | |
BM_HpackEncoderEncodeHeader<EmptyBatch>/0/16384 31 ns 31 ns 22189800 framing_bytes/iter:9 header_bytes/iter:0 | |
BM_HpackEncoderEncodeHeader<EmptyBatch>/1/16384 31 ns 31 ns 22162902 framing_bytes/iter:9 header_bytes/iter:0 | |
BM_HpackEncoderEncodeHeader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <x86intrin.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <inttypes.h> | |
static __inline__ uint64_t rdtsc(void){ | |
uint32_t hi, lo; | |
__asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); | |
return ( (uint64_t)lo)|( ((uint64_t)hi)<<32 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jdk.internal.platform.Metrics; | |
public class Foo { | |
static volatile long bah; | |
public static void main(String [] args) { | |
Metrics metrics = Metrics.systemMetrics(); | |
// com.sun.management.internal.OperatingSystemImpl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from PIL import Image | |
from math import sin, cos, pi | |
width = 1440 | |
height = 800 | |
midw = width / 2 | |
midh = height / 2 | |
lesser = min(midw, midh) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ordered = ["A", "B", "C", "D", "E", "F"] | |
def encode_permutation(permutation, ordered): | |
ordered = ordered.copy() | |
size = len(ordered) | |
encoded = 0 | |
for (i, value) in enumerate(permutation): | |
fact = factorial(size - i - 1) | |
idx = ordered.index(value) | |
ordered.remove(value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From https://datatracker.ietf.org/doc/html/draft-msporny-base58-03 | |
# The description on that page is misleading or just wrong. | |
# This was derived from converting the Rust code here: | |
# https://github.com/hachi-bitto/btc-wallet/blob/5dde65a262d3239a23292fc2a4a692994603aeb0/wallet/src/base58.rs | |
TABLE = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" | |
FORWARD = {k:v for (k, v) in enumerate(TABLE)} | |
BACK = {k:v for (v, k) in enumerate(TABLE)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From page 16 of https://ntruprime.cr.yp.to/nist/ntruprime-20201007.pdf | |
# Linked from https://www.imperialviolet.org/2021/08/26/qrencoding.html | |
def rebase(innums, indenoms, limit, newbase): | |
if len(innums) != len(indenoms): | |
raise "Bad" | |
syms = [] | |
if len(innums) == 1: | |
num, denom = innums[0], indenoms[0] | |
while denom > 1: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Benchmark (executor) (sleepMillis) (sleeps) Mode Cnt Score Error Units | |
SleeperBenchmark.Bench.run CACHED 1 1 ss 30 1.180 ± 0.028 ms/op | |
SleeperBenchmark.Bench.run CACHED 1 8 ss 30 1.227 ± 0.044 ms/op | |
SleeperBenchmark.Bench.run CACHED 1 64 ss 30 1.365 ± 0.045 ms/op | |
SleeperBenchmark.Bench.run CACHED 1 512 ss 30 3.764 ± 0.476 ms/op | |
SleeperBenchmark.Bench.run CACHED 1 4096 ss 30 13.375 ± 0.996 ms/op | |
SleeperBenchmark.Bench.run FIXED 1 1 ss 30 1.234 ± 0.035 ms/op | |
SleeperBenchmark.Bench.run FIXED 1 8 ss 30 1.362 ± 0.084 ms/op | |
SleeperBenchmark.Bench.run FIXED 1 64 ss 30 9.433 ± 0.409 ms/op |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Writes numbers less than 172 in one byte, numbers less than 1936 in 2 bytes. | |
private static void writeInt(OutputStream os, int i) throws IOException { | |
if (i < 0) { | |
throw new UnsupportedOperationException("no neg"); | |
} else if (i < 172) { | |
os.write((byte) i); | |
} else if (i < 1936) { | |
i -= 172; | |
os.write((byte)(172 + 42 + (i % 42))); | |
os.write((byte)(172 + (i / 42))); |