SHARE
TWEET

PythonJS fib test - native yield

a guest Dec 2nd, 2013 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function time() { return new Date().getTime() / 1000.0; };
  2. fib = function(n) {
  3.   var a, b;
  4.   var __r_0;
  5.   __r_0 = [0, 1];
  6.   a = __r_0[0];
  7.   b = __r_0[1];
  8.   var x;
  9.   x = 0;
  10.   while(( x ) < n) {
  11.     yield a;
  12.     var __r_1;
  13.     __r_1 = [b, (a + b)];
  14.     a = __r_1[0];
  15.     b = __r_1[1];
  16.     x += 1;
  17.   }
  18. }
  19.  
  20.  
  21. test = function() {
  22.   var a, t;
  23.   console.log("testing for over generator");
  24.   t = time();
  25.   a = undefined;
  26.   var i;
  27.   i = 0;
  28.   while(( i ) < 1000) {
  29.     var n, _i_;
  30.     __generator__ = fib(1000);
  31.     _i_ = 0;
  32.     while(( _i_ ) < 1000) {
  33.       n = __generator__.next();
  34.       a = n;
  35.       _i_ += 1;
  36.     }
  37.     i += 1;
  38.   }
  39.   console.log((time() - t));
  40.   console.log(a);
  41. }
RAW Paste Data
Want to get better at JavaScript?
Learn to code JavaScript in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top