Created
March 10, 2020 03:52
-
-
Save chuntaro/d53376707e27187635018a7d2ad5f9bb to your computer and use it in GitHub Desktop.
JavaScript で重複削除のテストコード
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
| let array = [...Array(50)].map(_ => Math.floor(Math.random() * 20)); | |
| let a = array.filter(function (x, i, self) { | |
| return self.indexOf(x) === i; | |
| }); | |
| let b = Array.from(new Set(array)); | |
| console.log(a, b); | |
| let loopCount = 1000000; | |
| console.time("filter"); | |
| for (let i = 0; i < loopCount; ++i) { | |
| let a = array.filter(function (x, i, self) { | |
| return self.indexOf(x) === i; | |
| }); | |
| } | |
| console.timeEnd("filter"); | |
| console.time("set"); | |
| for (let i = 0; i < loopCount; ++i) { | |
| let a = Array.from(new Set(array)); | |
| } | |
| console.timeEnd("set"); |
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
| $ node duplicate-removal.js | |
| [ | |
| 3, 9, 17, 11, 16, 14, 4, | |
| 6, 2, 12, 15, 7, 18, 1, | |
| 13, 19, 10, 8, 5 | |
| ] [ | |
| 3, 9, 17, 11, 16, 14, 4, | |
| 6, 2, 12, 15, 7, 18, 1, | |
| 13, 19, 10, 8, 5 | |
| ] | |
| filter: 1184.350ms | |
| set: 1253.351ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment