当前位置:网站首页>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>
边栏推荐
- Installation and functions of uview
- Delay queue `delayqueue`
- pytorch Default process group is not initialized
- How torch. gather works
- R 语言 基于关联规则与聚类分析的消费行为统计
- 将通讯录功能设置为数据库维护,增加用户名和密码
- Overview of database schema in tidb
- pytorch Default process group is not initialized
- Idea one click log generation
- boundvalueops和opsforvalue区别
猜你喜欢
[Software Engineering] software engineering review outline of Shandong University
正斜杠反斜杠的由来
从5秒优化到1秒,系统飞起来了...
Yarn create vite reports an error 'd:\program' which is neither an internal or external command nor a runnable program or batch file
2022 le fichier CISP - Pte (i) contient:
Solve the problem of win10 wsl2 IP change
2022 cisp-pte (I) document contains
[graduation season] graduation is the new beginning of your life journey. Are you ready
Configuring FTP, enterprise official website, database and other methods for ECS
在线文本数字识别列表求和工具
随机推荐
请问网页按钮怎么绑定sql语句呀
Construction of defense system for attack and defense exercises part II common strategies for responding to attacks
SQL injection bypass (I)
碎煤机crusher
Talk about Domain Driven Design
Apifox learning
How to download opencv? How to configure opencv after downloading?
Yolov6's fast and accurate target detection framework is open source
Overview of database schema in tidb
【Kevin三连弹之三】Rust真的比C慢吗?进一步分析queen微测评
Difference between boundvalueops and opsforvalue
【毕业季】毕业是人生旅途的新开始,你准备好了吗
面试官:请你介绍一下缓存穿透、缓存空值、缓存雪崩、缓存击穿的,通俗易懂
大学数据库mysql
Solve the problem of win10 wsl2 IP change
Vs how to configure opencv? 2022vs configuration opencv details (multiple pictures)
一线大厂面试官问:你真的懂电商订单开发吗?
程序人生 - 程序员三十五岁瓶颈你怎么看?
突破从0到1后,鲜花电商2.0时代怎么走?
攻防演习防御体系构建之第一篇之介绍和防守的四个阶段