Javascript的code使我的浏览器慢下来使我、浏览器、慢下来、Javascript

由网友(原来你什么都不要)分享简介:我写了WebWorkers图书馆和我想测试的区别在主页面线程中运行一个脚本之间,与一个或多个工人。现在的问题是:我能不能找到一个简短的功能,这将紧张我的浏览器,以至于我可以观察的差别的手I'm writing a library for WebWorkers, and I want to test the diffe...

我写了WebWorkers图书馆和我想测试的区别在主页面线程中运行一个脚本之间,与一个或多个工人。现在的问题是:我能不能找到一个简短的功能,这将紧张我的浏览器,以至于我可以观察的差别的手

I'm writing a library for WebWorkers, and I want to test the difference between running a script in the main page thread, versus in one or more workers. The problem is: I can't find out of hand a short function which will strain my browser enough that I can observe the difference.

一个快速搜索没有回多少,但它可能仅仅是因为我真的不知道的什么的搜索;通常我尝试优化我的code,不能让它慢...

A quick search didn't return much, but it might just be that I don't really know what to search for; usually I try to optimise my code, not make it slower...

我正在寻找算法或模式,可以以纯的Javascript容易地实现,即不依赖于DOM或XHR,并且其可具有传递限制或指定多远的计算去(无无限算法的参数); 1S<平均时间< 10秒。

I'm looking for algorithms or patterns that can be easily implemented in pure Javascript, that do not depend on the DOM or XHR, and which can have an argument passed to limit or specify how far the calculation goes (no infinite algorithms); 1s < avg time < 10s.

加分,如果它可以建立的不的递归和如果它不招致显著内存猪,同时仍然为处理器密集型尽可能

Extra points if it can be built without recursion and if it does not incur a significant memory hog while still being as processor intensive as possible.

推荐答案

尝试使用明显的(坏)递归实现了的 Fibonacci序列:

Try using the obvious (and bad) recursive implementation for the Fibonacci sequence:

function fib(x) {
  if (x <= 0) return 0;
  if (x == 1) return 1;
  return fib(x-1) + fib(x-2);
}

调用它的值〜30〜35(你的系统上完全不同)应在你所寻求的范围内产生了良好的减速时代。调用堆栈不应该得到非常深,该算法是像 O(2 ^ n)的

阅读全文

相关推荐

最新文章