{"id":16410244,"url":"https://github.com/danasilver/splice-pop-slice-perf","last_synced_at":"2025-06-14T22:40:23.978Z","repository":{"id":21650509,"uuid":"24971265","full_name":"danasilver/splice-pop-slice-perf","owner":"danasilver","description":"splice vs pop vs slice to create subsets of an array","archived":false,"fork":false,"pushed_at":"2014-10-11T04:20:09.000Z","size":240,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-06T00:41:55.018Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danasilver.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-09T03:00:37.000Z","updated_at":"2014-10-09T03:01:48.000Z","dependencies_parsed_at":"2022-08-21T22:01:01.777Z","dependency_job_id":null,"html_url":"https://github.com/danasilver/splice-pop-slice-perf","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danasilver%2Fsplice-pop-slice-perf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danasilver%2Fsplice-pop-slice-perf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danasilver%2Fsplice-pop-slice-perf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danasilver%2Fsplice-pop-slice-perf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danasilver","download_url":"https://codeload.github.com/danasilver/splice-pop-slice-perf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240405355,"owners_count":19796174,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T06:23:36.535Z","updated_at":"2025-02-24T02:25:43.161Z","avatar_url":"https://github.com/danasilver.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## slice vs pop vs slice to create subsets of an array\n\nOriginal array of size 10000.\n\nSmall subsets have size 2. Large subsets have size 1000.\n\nDoing multiple (2) pops is the fastest if the subsets are small, but calling pop\n1000 times for the large subset becomes a bottleneck.  Slice is fastest for a\nlarge subset.  Since slice doesn't modify the original array (unlike pop and\nsplice), after calling `Array.slice`, we set `Array.length -= n` where `n` is\nthe subset size.\n\n### Results\n```\nsplice (small subset) x 1,712 ops/sec ±0.70% (95 runs sampled)\nslice (small subset) x 1,572 ops/sec ±0.52% (96 runs sampled)\nmultiple pops (small subset) x 2,428 ops/sec ±1.06% (94 runs sampled)\nsplice (large subset) x 17,063 ops/sec ±0.50% (97 runs sampled)\nslice (large subset) x 15,644 ops/sec ±0.63% (95 runs sampled)\nmultiple pops (large subset) x 7,930 ops/sec ±0.34% (102 runs sampled)\nFastest is splice (large subset)\n```\n\n![Graph of results](results.png)\n\n### Summary\n\nUse pop if you only need to remove a few elements from the end of an array; use\nslice (or splice) if you need to remove a large number of elements.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanasilver%2Fsplice-pop-slice-perf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanasilver%2Fsplice-pop-slice-perf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanasilver%2Fsplice-pop-slice-perf/lists"}