Skip to content

Instantly share code, notes, and snippets.

View JobLeonard's full-sized avatar

Job van der Zwan JobLeonard

  • IxD/supporting programmer at Linnarsson Lab
  • Malmö
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>js-search indexing</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@JobLeonard
JobLeonard / index.html
Last active July 18, 2017 11:02
LZString old vs new vs "array trie" compression #jsbench #jsperf (http://jsbench.github.io/#a868adf796802a51a4e9add318572c70) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>LZString old vs new vs "array trie" compression #jsbench #jsperf</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@JobLeonard
JobLeonard / merge.js
Last active September 26, 2017 22:30
A dumb merge function for updating simple state trees in redux
/**
* Returns a new object that merges the values of
* `newObj` into `oldObj`. Uses shallow copying.
*
* **WARNING: Do NOT pass cyclical objects!
* This includes React nodes!**
*
* **IMPORTANT:** util.merge does **NOT** behave like
* lodash merge! *TL;DR:* (typed) arrays are not merged
* but replaced by the newer array.
@JobLeonard
JobLeonard / index.html
Last active October 2, 2017 23:50
Uint32Array - built-in sort vs radix #jsbench #jsperf (https://jsbench.github.io/#a2943f5f3baa8fe204d4a37cfd49dbef) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Uint32Array - built-in sort vs radix #jsbench #jsperf</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@JobLeonard
JobLeonard / StableSort.js
Last active October 24, 2017 08:03
Stable sort, in place and copy,
/**
* - `array`: array to be sorted
* - `compareFunc`: optional comparison callback that will be given
* *indices* i and j. This can be used to create callbacks that
* do more complex comparisons on objects in the array, and more
* importantly *other arrays*
* To ensure stability it should always end with `i - j`
* as the last sort key.
*
* Example:
@JobLeonard
JobLeonard / radix.js
Last active November 16, 2021 08:40
Radix sorts for TypedArrays, or arrays with values that would fit in 32-bit typed arrays. Outperforms built-in sort!
/*
By Job van der Zwan, CC0 2017
Inspired by Malte Skarupke's ska_sort[0], I wanted to see if radixSort sort is
also faster in JavaScript.
(Also, turns out I'm too dumb to implement ska_sort, so I used the more
simple LSB radixSort sort instead. It is based on an implementation by
Victor J. Duvanenko, but cleaned up to remove a lot of redundancies,
updated for ES6, and making use of TypedArrays for better performance.
@JobLeonard
JobLeonard / index.html
Created December 5, 2017 17:18
join vs concat when dealing with very long lists of single-character strings (http://jsbench.github.io/#26d1f3705b3340ace36cbad7b24055fb) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>join vs concat when dealing with very long lists of single-character strings</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@JobLeonard
JobLeonard / index.html
Created December 5, 2017 17:23
Join vs Template - Venryx (http://jsbench.github.io/#7f03c3d3fdc9ae3a399d0f2d6de3d69f) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Join vs Template - Venryx</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@JobLeonard
JobLeonard / lzuint8array.js
Last active February 16, 2023 18:46
Uint8Array to LZ-string and back
const LZuint8Array = (function () {
/*
basic ranges of printable UTF16 values (as found in LZ-string):
[32, 127), [160, 55296), [63744, 65536)
We also have filter out string characters like:
" (34)
' (39)
` (44)
(Forward tick is safe: ´ (96))
So:
@JobLeonard
JobLeonard / index.html
Last active July 4, 2018 13:50
LZ-string 1.4.4 vs two variants of LZ-string 2 #jsbench #jsperf (http://jsbench.github.io/#d9b4022f73da492adff640c1afe224a0) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>LZ-string 1.4.4 vs two variants of LZ-string 2 #jsbench #jsperf</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>