SHARE
TWEET

PythonJS fib test - generated yield

a guest Dec 2nd, 2013 57 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.   this.n = n;
  4.   var __r_0;
  5.   __r_0 = [0, 1];
  6.   this.a = __r_0[0];
  7.   this.b = __r_0[1];
  8.   this.__iter_start = 0;
  9.   this.__iter_index = 0;
  10.   this.__iter_end = this.n;
  11.   this.__done__ = 0;
  12. }
  13.  
  14. fib.prototype.next = function() {
  15.   if (( this.__iter_index ) < this.__iter_end) {
  16.     __yield_return__ = this.a;
  17.     var __r_1;
  18.     __r_1 = [this.b, (this.a + this.b)];
  19.     this.a = __r_1[0];
  20.     this.b = __r_1[1];
  21.     this.__iter_index += 1
  22.     if (( this.__iter_index ) == this.__iter_end) {
  23.       this.__done__ = 1;
  24.     }
  25.     return __yield_return__;
  26.   } else {
  27.     this.__done__ = 1;
  28.   }
  29. }
  30.  
  31. test = function(args, kwargs) {
  32.   var a, t;
  33.   console.log("testing for over generator");
  34.   t = time();
  35.   a = undefined;
  36.   var __iterator__, i;
  37.   var i;
  38.   i = 0;
  39.   while(( i ) < 1000) {
  40.     var __iterator__, n;
  41.     var n, __generator__;
  42.     __generator__ = new fib(1000);
  43.     while(( __generator__.__done__ ) != 1) {
  44.       n = __generator__.next();
  45.       a = n;
  46.     }
  47.     i += 1
  48.   }
  49.   console.log((time() - t));
  50.   console.log(a);
  51. }
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