for and while
来源:互联网 发布:linux同名文件夹合并 编辑:程序博客网 时间:2024/06/10 23:13
for和while都是循环,至于怎么实现的,不了解;性能如何,且看下文;
以数组去重为例子;先生产一个有100000000数字1数组;
function create() { var arr = []; for (var i = 0; i < 100000000; i++) { arr[i] = 1; } return arr;}
for数组去重,因为性能根本不够,这里不考虑for (var k in arr);
function delrepeat1() { var arr = create(); if (arr instanceof Array === false) { return false } else { var json = {}, len = arr.length, result = []; for (; len>0; len--) { if (!json[arr[len]]) { json[arr[len]] = 1; result.push(arr[len]) } } return result }}
while去重:
function delrepeat2() { var arr = create(); if (arr instanceof Array === false) { return false } else { var json = {}, len = arr.length, result = []; while (len--) { if (!json[arr[len]]) { json[arr[len]] = 1; result.push(arr[len]) } } return result }}
统计时间
function time(f) { console.time("a"); f(); console.timeEnd("a");}
这里分别执行5次:
time(deleRepeat1);
结果如下:
看结果没有区别,不过这个结果肯定是不准的;所以今天没有结论,日后在写;
阅读全文
0 0
- For And While
- for and while
- do... while,while and for 循环
- One example for learning "for and while"
- for.VS.while loop (advantages and disadvantages)
- 第十三章 while and for Loops
- for 循环 and while 循环(二)
- for 循环 and while 循环(三)
- for 循环 and while 循环(四)
- Linux shell 循环for and while
- while and for Loops--Learning Python-Chapter 13
- while for
- for、while
- for while do while continue
- while、do while、for循环
- for while do while区别
- 循环:for、while、do-while
- while and do while; i++ and ++i
- python 数据科学
- angularJs 增加 删除 排序
- Html之frameset,iframe框架之间如何互相调用变量、函数-yellowcong
- 顺时针打印矩阵
- PostgreSQL入门到精通——世界上功能最强大的开源数据库
- for and while
- qemu结合gdb调试龙芯1c的裸机程序helloworld
- jquery简单的用户名密码验证
- 渗透技巧之ssh
- 【干货技术贴】之-mac下如何安装WebStorm + 破解
- Jmeter接口测试+压力测试
- Mathematics for 3D Game Programming and Computer Graphics基础学习
- 课程表(div)
- Maven提高篇系列之(二)——配置Plugin到某个Phase(以Selenium集成测试为例)