当前位置:网站首页>How to view program running time (timer) in JS

How to view program running time (timer) in JS

2022-06-27 07:35:00 I am the sun?

We can add... At the beginning of the code to be tested :
console.time(“ Timer name ”);
Add at the end of the test code :
console.timeEnd(“ Timer name ”);
The following code :

<!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 + "&nbsp;&nbsp;&nbsp;&nbsp;");
					sum++;
			}
		}
		document.write("<br /> Primes in all :" + sum +  "  individual .");
		console.timeEnd("test");
	</script>
</head>
<body>
	
</body>
</html>

 Insert picture description here

原网站

版权声明
本文为[I am the sun?]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/178/202206270720099403.html