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
// fast random number generator with better distribution | |
function Mash() { | |
var n = 0xefc8249d; | |
var mash = function(data) { | |
data = data.toString(); | |
for (var i = 0; i < data.length; i++) { | |
n += data.charCodeAt(i); | |
var h = 0.02519603282416938 * n; | |
n = h >>> 0; |
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
// fast array sort | |
function heap3Sort() { | |
function swap(ary, a, b) { | |
var t = ary[a]; | |
ary[a] = ary[b]; | |
ary[b] = t; | |
} | |
function shiftDown(ary, start, end) { | |
var root = start, | |
child, s, root21; |
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
const quickSort = (function() { | |
var i = 0; | |
function swap(first, second, array) { | |
var temp = array[first]; | |
array[first] = array[second]; | |
array[second] = temp; | |
} | |
return function(array) { | |
for (var len = array.length - 1; i < len; i++) { |
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
firstNotRepeatingCharacter = s => { | |
r = {} | |
for (e of s) | |
// ~n = -(n+1) | |
// -~n = n+1 | |
// ~ undefined = -1 | |
// -~undefined = 1 | |
// if character is in hash increment else set to 1 | |
r[e] = -~r[e] | |
for (e in r) |
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
function deepCompare(o1, o2) { | |
if (typeof o1 !== "object" || o1 === null) return o1 === o2; // fast obj/null test | |
let n; | |
if (o1 instanceof Array) { // fast array test | |
const l = o1.length; | |
for (let i = 0; i < l; i++) { | |
if (deepCompare(o1[i], o2[i])) {} else { | |
return false | |
} | |
} |
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
#user nobody; | |
worker_processes 2; | |
#error_log logs/error.log; | |
#error_log logs/error.log notice; | |
#error_log logs/error.log info; | |
#pid logs/nginx.pid; | |
pid /run/nginx.pid; |
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
function arrayHistogram(arr){ | |
const obj={}; | |
for(let i=0;i<arr.length;i++){ | |
if(!obj.hasOwnProperty(arr[i])) obj[arr[i]]=0; | |
obj[arr[i]]++; | |
} | |
return obj; | |
} |
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
// Check for existence of property in deeply nested object | |
function get_if_exist(str) { | |
try { return eval(str) } | |
catch(e) { return undefined } | |
} | |
//slightly slower | |
function objHasKeys(obj, keys) { | |
var next = keys.shift(); | |
return obj[next] && (! keys.length || objHasKeys(obj[next], keys)); | |
} |
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
Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 | |
Mozilla/5.0 (Linux; U; Android 4.0.3; de-ch; HTC Sensation Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 | |
Mozilla/5.0 (Linux; U; Android 2.3; en-us) AppleWebKit/999+ (KHTML, like Gecko) Safari/999.9 | |
Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn; HTC_IncredibleS_S710e Build/GRJ90) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 | |
Mozilla/5.0 (Linux; U; Android 2.3.5; en-us; HTC Vision Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 | |
Mozilla/5.0 (Linux; U; Android 2.3.4; fr-fr; HTC Desire Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 | |
Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; T-Mobile myTouch 3G Slide Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 | |
Mozilla/5.0 (Linux; U; Android 2.3.3; zh-tw; HTC_Pyramid Build/G |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"/> | |
<title>compare</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> |
OlderNewer