当前位置:网站首页>js中如何查看程序运行时间(计时器)
js中如何查看程序运行时间(计时器)
2022-06-27 07:20:00 【I am the sun?】
我们可以在要测试代码的最前面加上:
console.time(“计时器名字”);
测试代码最后加上:
console.timeEnd(“计时器名字”);
如下代码:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<script type="text/javascript">
console.time("test");
var sum = 0;
for(var i = 1;i <= 100;i++){
var flag = true;
if(i == 1)
flag = false;
for(var j = 2;j < i;j++){
if(i % j == 0){
flag = false;
break;
}
}
if(flag){
document.write(i + " ");
sum++;
}
}
document.write("<br />质数一共有:" + sum + " 个。");
console.timeEnd("test");
</script>
</head>
<body>
</body>
</html>

边栏推荐
- 高薪程序员&面试题精讲系列116之Redis缓存如何实现?怎么发现热key?缓存时可能存在哪些问题?
- 【编译原理】山东大学编译原理复习提纲
- 请问如何在网页通过excel文件的形式向后段数据库添加数据
- 面试官:用分库分表如何做到永不迁移数据和避免热点问题?
- 通过uview让tabbar根据权限显示相应数量的tabbar
- 2022 le fichier CISP - Pte (i) contient:
- Vs how to configure opencv? 2022vs configuration opencv details (multiple pictures)
- How to implement redis cache of highly paid programmers & interview questions series 116? How do I find a hot key? What are the possible problems with caching?
- MySQL
- 磁选机是什么?
猜你喜欢

Winow10 installation nexus nexus-3.20.1-01

MySQL

进程终止(你真的学会递归了吗?考验你的递归基础)

面试官:用分库分表如何做到永不迁移数据和避免热点问题?

mssql如何使用语句导出并删除多表数据

Xiaomi Interviewer: let's talk about the proficient Registration Center for three days and three nights

Vs how to configure opencv? 2022vs configuration opencv details (multiple pictures)

【Kevin三连弹之三】Rust真的比C慢吗?进一步分析queen微测评

What is the difference between volatile and synchronized?

如何优雅的写 Controller 层代码?
随机推荐
JDBC reads MySQL data list
Process termination (have you really learned recursion? Test your recursion Foundation)
语音合成:Tacotron详解【端到端语音合成模型】【与传统语音合成相比,它没有复杂的语音学和声学特征模块,而是仅用<文本序列,语音声谱>配对数据集对神经网络进行训练,因此简化了很多流程】
Visual studio vs shortcut key usage
小米面试官:听你说精通注册中心,我们来聊 3 天 3 夜
What is the difference between volatile and synchronized?
Hutool symmetric encryption
volatile 和 synchronized 到底啥区别?
大学数据库mysql
JDBC操作Mysql示例
Centos7.9 install MySQL 5.7 and set startup
Apifox learning
How to implement redis cache of highly paid programmers & interview questions series 116? How do I find a hot key? What are the possible problems with caching?
【毕业季】毕业是人生旅途的新开始,你准备好了吗
postgreSQL在windows系统遇到权限否认(permission denied)
Yarn create vite reports an error 'd:\program' which is neither an internal or external command nor a runnable program or batch file
uview的安装和功能
一线大厂面试官问:你真的懂电商订单开发吗?
webscoket 数据库监听
VNC Viewer方式的远程连接树莓派