Created
January 15, 2018 03:28
-
-
Save compilerexe/74f783e4bb94513163f7d9fdaba0b8b3 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/qeneyin
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"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<script type="text/javascript" | |
src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var iterations = 100000 | |
var items = [] | |
console.log('/*--------------------*/') | |
console.time('#1') | |
for (var i = 0; i < iterations; i++) { | |
items.push({id: i, number: parseInt(Math.random() * 1000).toFixed(0)}) | |
} | |
console.log('Add objects to array completed in ') | |
console.timeEnd('#1') | |
console.log('/*--------------------*/') | |
console.time('#2') | |
var uniqItems = _.uniq(items, function (item) { | |
return item.number | |
}) | |
console.log('result filter items : ', uniqItems.length) | |
console.log('Called _.uniq completed in ') | |
console.timeEnd('#2') | |
console.log('/*--------------------*/') | |
console.time('#3') | |
var unique = {} | |
var distinct = [] | |
for (var k in items) { | |
if (typeof(unique[items[k].number]) === 'undefined') { | |
distinct.push({id: items[k].id, number: items[k].number}) | |
unique[items[k].number] = true | |
} | |
} | |
console.log('result filter items : ', distinct.length) | |
console.log('Javascript uniqe items completed in ') | |
console.timeEnd('#3') | |
console.log('/*--------------------*/') | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var iterations = 100000 | |
var items = [] | |
console.log('/*--------------------*/') | |
console.time('#1') | |
for (var i = 0; i < iterations; i++) { | |
items.push({id: i, number: parseInt(Math.random() * 1000).toFixed(0)}) | |
} | |
console.log('Add objects to array completed in ') | |
console.timeEnd('#1') | |
console.log('/*--------------------*/') | |
console.time('#2') | |
var uniqItems = _.uniq(items, function (item) { | |
return item.number | |
}) | |
console.log('result filter items : ', uniqItems.length) | |
console.log('Called _.uniq completed in ') | |
console.timeEnd('#2') | |
console.log('/*--------------------*/') | |
console.time('#3') | |
var unique = {} | |
var distinct = [] | |
for (var k in items) { | |
if (typeof(unique[items[k].number]) === 'undefined') { | |
distinct.push({id: items[k].id, number: items[k].number}) | |
unique[items[k].number] = true | |
} | |
} | |
console.log('result filter items : ', distinct.length) | |
console.log('Javascript uniqe items completed in ') | |
console.timeEnd('#3') | |
console.log('/*--------------------*/')</script></body> | |
</html> |
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
var iterations = 100000 | |
var items = [] | |
console.log('/*--------------------*/') | |
console.time('#1') | |
for (var i = 0; i < iterations; i++) { | |
items.push({id: i, number: parseInt(Math.random() * 1000).toFixed(0)}) | |
} | |
console.log('Add objects to array completed in ') | |
console.timeEnd('#1') | |
console.log('/*--------------------*/') | |
console.time('#2') | |
var uniqItems = _.uniq(items, function (item) { | |
return item.number | |
}) | |
console.log('result filter items : ', uniqItems.length) | |
console.log('Called _.uniq completed in ') | |
console.timeEnd('#2') | |
console.log('/*--------------------*/') | |
console.time('#3') | |
var unique = {} | |
var distinct = [] | |
for (var k in items) { | |
if (typeof(unique[items[k].number]) === 'undefined') { | |
distinct.push({id: items[k].id, number: items[k].number}) | |
unique[items[k].number] = true | |
} | |
} | |
console.log('result filter items : ', distinct.length) | |
console.log('Javascript uniqe items completed in ') | |
console.timeEnd('#3') | |
console.log('/*--------------------*/') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment