Skip to content

Instantly share code, notes, and snippets.

@addaleax
addaleax / latin1_utf8bytecount.ts
Created December 5, 2022 00:02
ISO-8859-1 to UTF-8 byte length counter
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <emmintrin.h>
#include <immintrin.h>
// header
extern "C" {
size_t utf8_length_for_latin1_str(const uint8_t* latin1_str, size_t latin1_len);
}
@addaleax
addaleax / utf8_latin1.cpp
Last active December 1, 2022 00:24
UTF-8 to ISO-8859-1 [aka Latin1] converters with gcc-style SIMD C++
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <emmintrin.h>
#include <immintrin.h>
// header
extern "C" {
// Returns true if str can be converted to latin1.
bool utf8_can_be_converted_to_latin1(const uint8_t* str, size_t len);
@addaleax
addaleax / bench.js
Created August 11, 2020 12:47
Private vs Symbol vs Plain property comparison
function bench(name, fn) {
const a = process.hrtime.bigint();
for (let i = 0; i < 1e7; i++)
fn();
const seconds = Number(process.hrtime.bigint() - a) / 1e9;
console.log({ name, seconds });
}
class Private {
#privateProp = 0;
@addaleax
addaleax / track-buffer-pool-usage.js
Created November 24, 2019 00:31
Buffer pool usage tracker
'use strict';
const orig = Buffer.allocUnsafe;
const stats = {
inUse: 0,
allocated: 0
};
const group = new FinalizationGroup((holdings) => {
for (const info of holdings) {
diff --git a/deps/v8/include/libplatform/v8-tracing.h b/deps/v8/include/libplatform/v8-tracing.h
index e7cd8bfcdb66..df145e95bf72 100644
--- a/deps/v8/include/libplatform/v8-tracing.h
+++ b/deps/v8/include/libplatform/v8-tracing.h
@@ -244,6 +244,8 @@ class V8_PLATFORM_EXPORT TracingController
TracingController();
~TracingController() override;
+
+ // Takes ownership of |trace_buffer|.
'use strict';
const fs = require('fs').promises;
const child_process = require('child_process');
const kPIDSpace = 100000;
const kSetupParallelism = 100;
async function createUnwritableFile(filename) {
try {
await fs.unlink(filename);
@addaleax
addaleax / keybase.md
Created May 26, 2017 20:59
keybase.md

Keybase proof

I hereby claim:

  • I am addaleax on github.
  • I am addaleax (https://keybase.io/addaleax) on keybase.
  • I have a public key ASA6TkRUs_sUB4bBkhE4Y4s-Y70CA3syT1JaDOi3w5u1Iwo

To claim this, I am signing this object:

@addaleax
addaleax / analyzed-benchmarks.csv
Created December 12, 2016 16:20
Benchmark results for “buffer: allow Uint8Array input to methods”
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
improvement significant p.value
buffers/buffer-base64-decode.js 0.33 % 4.989959e-01
buffers/buffer-base64-encode.js -0.26 % 5.876859e-01
buffers/buffer-bytelength.js n=5000000 len=16 encoding="base64" -0.20 % 5.174388e-01
buffers/buffer-bytelength.js n=5000000 len=16 encoding="utf8" -0.18 % 4.589270e-01
buffers/buffer-bytelength.js n=5000000 len=1 encoding="base64"