javascript - js数组去重方法如何进行性能对比
ringa_lee
ringa_lee 2017-04-11 11:31:10
[JavaScript讨论组]

收集了几种数组去重方法,但是在对比性能的时候,原本采取对同一数组去重100000次,后来想到会不会浏览器对同一数组的去重会缓存起来,能说明这种性能对比方法的正确性么,或者提供比较好的方法给我


let arr1 = [1, 1, 1, 2, 3, 2, 4];
let es6 = function() {
    for(let i = 100000; i > 0; i--){
        let array = Array.from(new Set(arr1));
    }
};
console.time('es6');
console.timeEnd('es6');
let es5 = arr => { 
    for(let i = 100000; i > 0; i--){
        arr1.filter(function (value, index, array) { return index <= array.indexOf(value);}); 
    }
};
console.time('es5');
console.timeEnd('es5');
ringa_lee
ringa_lee

ringa_lee

全部回复(1)
大家讲道理

使用Benchmark.js和jsPerf分析代码性能
这篇文章介绍了工具Benchmark.jsjsPerf,不过后者挂了好久。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号