Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function a(input) {
- var index = [];
- var item;
- for (var i=0; i<input.length; i++) {
- item = input[i];
- if (index.indexOf(item) === -1) {
- index.push(item);
- }
- }
- return index;
- }
- function b(input) {
- var index = {};
- var item;
- for (var i=0; i<input.length; i++) {
- item = input[i];
- if (index[item] === undefined) {
- index[item] = true;
- }
- }
- return index;
- }
- function c(input) {
- var index = {};
- var item;
- for (var i=0; i<input.length; i++) {
- item = input[i];
- index[item] = true;
- }
- return index;
- }
- function test(f, input, times) {
- for (var i=0; i<times; i++) {
- f(input());
- }
- }
- function first(amount) {
- return function() {
- var data = [];
- for (var i=0; i<amount; i++) {
- data.push(i);
- }
- return data;
- }
- }
- function random(amount, range) {
- return function() {
- var data = [];
- for (var i=0; i<amount; i++) {
- data.push(Math.floor(Math.random()*range));
- }
- return data;
- }
- }
- var testAmount = 1000;
- var testRange = 100;
- var testTimes = 10000;
- console.log('amount, range, times');
- console.log(testAmount+', '+testRange+', '+testTimes);
- console.log('--------------------')
- console.time('a'); test(a, random(testAmount, testRange), testTimes); console.timeEnd('a');
- console.time('b'); test(b, random(testAmount, testRange), testTimes); console.timeEnd('b');
- console.time('c'); test(c, random(testAmount, testRange), testTimes); console.timeEnd('c');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement