This repository has been archived by the owner. It is now read-only.

# cho45/jsdeferred

markdown

cho45 committed Mar 16, 2012
1 parent fc23d0b commit ab51a9c330e492fc9812aaf38c3b8861fe792bd4
Showing with 4 additions and 259 deletions.
2. +3 −28 index.html
 @@ -413,9 +413,9 @@

"Speeding Up" JavaScript

Automatically Divide a Long Loop

loop() function is effective when each loop is a heavy process. However, when a single loop is not so heavy but the number of iteration is numerous, it's not efficient. - Here I define a function called aloop()

+ Here I define a function called repeat()

-function aloop (n, f) {
+function repeat (n, f) {
var i = 0, end = {}, ret = null;
return Deferred.next(function () {
var t = (new Date()).getTime();
@@ -585,32 +585,7 @@

Divided Loop

Auto Divided Loop

-function aloop (n, f) {
-    var i   = 0;
-    var end = new Object;
-    var ret = null;
-    return Deferred.next(function () {
-        var t = (new Date()).getTime();
-        try {
-            do {
-                ret = f(i)
-                i++;
-                if (i >= n) throw end;
-            } while ((new Date()).getTime() - t < 50);
-            console.log("Devided: " + ((new Date()).getTime() - t) + "msec.");
-            return Deferred.call(arguments.callee);
-        } catch (e) {
-            if (e == end) {
-                console.log("End");
-                return ret;
-            } else {
-                throw e;
-            }
-        }
-    });
-}
-
-aloop(100, function (n, o) {
+Deferred.repeat(100, function (n, o) {
console.log(n);
for (var i = 0; i < Math.pow(n, 2); i++) {
for (var j = n; j; j--);