Created
May 24, 2021 18:26
-
-
Save billycromb/7d7ac6354b8e0093f38c652f3d80eeaf to your computer and use it in GitHub Desktop.
measure_filter_rig
This file contains hidden or 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
| 'use strict'; | |
| (function() { | |
| function filterArray(users) { | |
| return Object.fromEntries( | |
| users.filter(user => user.active) | |
| .map(user => [user.name, null]) | |
| ); | |
| } | |
| function randomName(length) { | |
| const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
| const charactersLength = characters.length; | |
| let res = '' | |
| for (let i = 0; i < length; i++) { | |
| res = res + characters.charAt(Math.floor(Math.random() * charactersLength)) | |
| } | |
| return res; | |
| } | |
| function randomBool() { | |
| return (Math.floor(Math.random() * 2) == 0); | |
| } | |
| function setup() { | |
| let users = []; | |
| for (let i = 0; i < 10000000; i++) { | |
| users[i] = {name: randomName(8), active: randomBool()} | |
| } | |
| return users; | |
| } | |
| function doBench() { | |
| console.log('starting bench'); | |
| let a = setup(); | |
| console.log('done setup'); | |
| let then = new Date(); | |
| let b = filterArray(a); | |
| let now = new Date(); | |
| console.log(now-then); | |
| } | |
| doBench(); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment