var getTimeInMs() = function () {
      var date = new Date();
      return date.getTime();
var str = "I'm a short string after all.",
      newStr = "",
      appends = 15000,
      stime = getTimeInMs();
      while (appends--) {
            newStr += str;
      alert(getTimeInMs() - stime);
var appends = 15000,
      stime = getTimeInMs(),
      arr = [];
      while (appends--) {
      newStr = arr.join("");
      alert(getTimeInMs() - stime);




IE7 and earlier use an inferior implementation of concatenation in which each pair of concateated strings always be copied to a new memory location. …. IE7’s naive concatenation algorithm requires that the browser repeatedly copy and allocate memory for larger and larger strings each time through the loop. The result is quadratic running time and memory consumption.

A Rule of Thumb When DOM Scripting

原则是:尽可能的不要接触DOM(touch the DOM lightly, and stay within ECMAScript as much as possible).

Here is an example

function aBadInnerHTMLLoop() {
    for (var i = 0; i < 15000; i++) {
        document.getElementById('here').innerHTML += 'a';


function aBetterInnerHTMLLoop() {
    var str = '';
    for (var i = 0; i < 15000; i++) {
        str += 'a';
    document.getElementById('here').innerHTML = str;


下面我引用一段文献[High Performance JavaScript]来说明为什么DOM的执行如此低下。

DOM in the Browser World
The Document Object Model(DOM) is a language-independent application interface(API) for working with XML and HTML documents. … so it’s common across browsers to keep DOM and JavaScript implementions indepent of each other, this makes DOM scripting inherently slow. Because simply having two separate pieces of functionality interfaceing with eath other will always come at a cost. An excellent analogy is to think of DOM as piece of land and JavaScript as another piece of land, both connected with a toll bridge. Every time your EMACScript needs access to the DOM, you have to cross this bridge and pay the performance toll fee. The more you work with the DOM, the more you pay So the general recommendation is to cross that bridge as few times as possible and strive to stay in ECMAScript land.


[root@localhost ~]# which date
[root@localhost ~]# which date less vi emacs
/usr/bin/which: no emacs in (/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root@localhost ~]# type date
date is /bin/date


Tonitech版权所有 | 转载请注明出处:


        在升级WordPress中的插件的时候,半天没有更新完,感觉好像卡了,于是打开首页,发现页面只有提示“正在执行例行维护,请一分钟后回来”。发现,网上很多人说要修改/wp_admin/includes/class-wp-filesystem-direct.php 文件,不过这里有一个快速的解决方案:在FTP 根目录下找到名为 .maintenance的文件,删了就ok,刷新一下页面,一切都正常了。


Tonitech版权所有 | 转载请注明出处: