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>Array vs. Linked List #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> |
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 copyAndIncrement(arr) { | |
const copy = arr.slice(); | |
copy[0] += 1; | |
return copy; | |
} | |
function spoil() { | |
const objThatSpoilsEverything = {}; | |
objThatSpoilsEverything.value = 1.5; | |
} |
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 countDistinct(items) { | |
var result = []; | |
for (var i = 0, l = items.length; i < l; ++i) { | |
var item = items[i]; | |
var index = -1; | |
for (var j = 0; j < result.length; ++j) { | |
var existing = result[j]; | |
if (item === existing[0]) { | |
index = j; | |
break; |
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 sub(pattern, string, repl) { | |
// Substitute all matches of pattern in string with the value returned by repl | |
// given a match and the corresponding group values, | |
// similar to Python's re.sub function. | |
// Note that pattern must be a "global" RegExp of the form /.../g | |
var found; | |
var lastIndex = 0; | |
var result = ""; | |
while (found = pattern.exec(string)) { | |
var subst = repl.apply(this, found); |
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 cached(func) { | |
cache = {}; | |
return function() { | |
var args = []; | |
for (var i = 0; i < arguments.length; ++i) | |
args.push(arguments[i]); | |
var key = $.param({args: args}); | |
var value = cache[key]; | |
if (typeof value != "undefined") | |
return 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
class BulkInsertion(object): | |
""" | |
Bulk-insert several model instances using accumulated DB statements. | |
Usage: | |
>>> with BulkInsertion('app_tablename') as inserter: | |
... inserter.insert(field1=value1, field2=value2) | |
By default, a DB statement is issued every 1000 inserts. | |