Abd*_*aly 7 javascript synchronous blocking
我试图嘲笑一种方法,这种方法需要很长时间才能用于测试,但是无法在Javascript中找到一种很好的方法.除了编写一个非常长的for循环之外还有什么好方法
检查时间的循环怎么样?
function sleep(milliSeconds){
var startTime = new Date().getTime(); // get the current time
while (new Date().getTime() < startTime + milliSeconds); // hog cpu until time's up
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5568 次 |
| 最近记录: |