当前位置:网站首页>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>

边栏推荐
- pytorch Default process group is not initialized
- guava 教程收集一些案例慢慢写 google工具类
- 程序人生 - 程序员三十五岁瓶颈你怎么看?
- 磁选机是什么?
- 【Kevin三连弹之三】Rust真的比C慢吗?进一步分析queen微测评
- guava 定时任务
- R language calculates Spearman correlation coefficient in parallel to speed up the construction of co occurrence network
- How torch.gather works
- Easyexcel: read Excel data into the list set
- volatile 和 synchronized 到底啥区别?
猜你喜欢

Yarn create vite reports an error 'd:\program' which is neither an internal or external command nor a runnable program or batch file

IDEA连接数据库报错

Some settings about postfix completion code template in idea

2022 le fichier CISP - Pte (i) contient:

2022 CISP-PTE(一)文件包含

磁选机是什么?

在线文本数字识别列表求和工具

How to download opencv? How to configure opencv after downloading?

Solve the problem of win10 wsl2 IP change

云服务器配置ftp、企业官网、数据库等方法
随机推荐
R 语言并行计算 spearman 相关系数,加快共现网络(co- occurrence network)构建速度
mysql关于自增和不能为空
一线大厂面试官问:你真的懂电商订单开发吗?
postgreSQL在windows系统遇到权限否认(permission denied)
延时队列`DelayQueue`
guava 定时任务
高薪程序员&面试题精讲系列116之Redis缓存如何实现?怎么发现热key?缓存时可能存在哪些问题?
Bean拷贝详解
From 5 seconds to 1 second, the system flies
JDBC读取Mysql数据列表
用XGBoost迭代读取数据集
【编译原理】山东大学编译原理复习提纲
云服务器配置ftp、企业官网、数据库等方法
Park and unpark in unsafe
win10远程连接云服务器
[leetcode] day90 the element with the smallest K in the binary search tree
(已解决) npm突然报错 Cannot find module ‘D:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js‘
mssql如何使用语句导出并删除多表数据
Interviewer: do you have any plan to request a lot of data that does not exist in redis to destroy the database?
Overview of database schema in tidb