Skip to content

Instantly share code, notes, and snippets.

// This program have to set node.js option --expose-gc
// ex) $ node --expose-gc string_serializer_benchmark.js
const strbase = "abあいAB##11";
function bufferFromCommon(encode, join, repeat) {
const str = strbase.repeat(join);
console.time(`Buffer.from(${encode})`);
const newbuf = new ArrayBuffer(str.length * 3 * repeat);
const newview = new Uint8Array(newbuf);
@ayatty
ayatty / roJson.js
Created March 17, 2020 16:50
JavaScript Object to Binary Serializer with key Index
const stringHash = require("string-hash");
// 型識別子
const typeToId = {
object: 1 * 16,
denseArray: 2 * 16,
sparseArray: 3 * 16,
string: 4 * 16,
uint4: 5 * 16,
number: 6 * 16,
@ayatty
ayatty / PartMatchIndex.js
Last active April 5, 2019 03:25
JS Part of string search index for Array of string(exclude ASCII)
function _addIndex(character, lineNum, indexMap) {
let indexValue = indexMap.get(character);
if (!indexValue) {
indexValue = new Set();
indexMap.set(character, indexValue);
}
indexValue.add(lineNum);
}
class PartMatchIndex {
@ayatty
ayatty / node_thread.js
Created March 14, 2019 15:21
Thread like context for Node.js (using async_hooks)
const asyncHooks = require('async_hooks');
const asyncMap = {}
asyncHooks.createHook({
init(asyncId, type, triggerAsyncId) {
const parent = asyncHooks.executionAsyncId();
// 親がスレッドに属していれば子も属す
if (asyncMap[parent]) {
asyncMap[asyncId] = asyncMap[parent];