home *** CD-ROM | disk | FTP | other *** search
/ Champak 48 / cdrom_image.iso / Games / bobsleddin.swf / scripts / __Packages / PerformanceTest.as < prev    next >
Encoding:
Text File  |  2007-09-28  |  1.9 KB  |  78 lines

  1. class PerformanceTest
  2. {
  3.    var remainingLoops;
  4.    var onComplete;
  5.    var flashMajorVersion;
  6.    var flashMinorVersion;
  7.    var intervalID;
  8.    var log;
  9.    var processor;
  10.    var score = 0;
  11.    var time = 0;
  12.    var loops = 20;
  13.    var complete = false;
  14.    function PerformanceTest(itterations, onComplete)
  15.    {
  16.       if(itterations)
  17.       {
  18.          this.loops = itterations;
  19.       }
  20.       this.remainingLoops = this.loops;
  21.       if(onComplete)
  22.       {
  23.          this.onComplete = onComplete;
  24.       }
  25.       var _loc2_ = System.capabilities.version.substr(4).split(",");
  26.       this.flashMajorVersion = Number(_loc2_[0]);
  27.       this.flashMinorVersion = Number(_loc2_[2]);
  28.       this.complete = false;
  29.       this.intervalID = setInterval(function(o)
  30.       {
  31.          o.test();
  32.       }
  33.       ,0,this);
  34.    }
  35.    function test()
  36.    {
  37.       if(this.remainingLoops <= 0)
  38.       {
  39.          this.finalize();
  40.          clearInterval(this.intervalID);
  41.          return undefined;
  42.       }
  43.       this.remainingLoops = this.remainingLoops - 1;
  44.       var _loc4_ = getTimer();
  45.       var _loc3_ = undefined;
  46.       var _loc2_ = 0;
  47.       while(_loc2_ < 6400)
  48.       {
  49.          _loc3_ = {};
  50.          _loc2_ = _loc2_ + 1;
  51.       }
  52.       this.time += getTimer() - _loc4_;
  53.    }
  54.    function finalize()
  55.    {
  56.       this.score = Math.floor(this.loops / this.time * 10000);
  57.       if(this.flashMajorVersion >= 7)
  58.       {
  59.          this.log = Math.log(this.score * 0.015);
  60.       }
  61.       else
  62.       {
  63.          this.log = Math.log(this.score * 0.023);
  64.       }
  65.       this.processor = this.log * 1000;
  66.       this.complete = true;
  67.       this.onComplete(this);
  68.    }
  69.    function toString()
  70.    {
  71.       if(this.score)
  72.       {
  73.          return "Loops:\t" + this.loops + "\nFlash Version: \t" + System.capabilities.version + "\nTotal Time:\t" + this.time + "\nScore: \t" + this.score + "\nProcessor: \t" + this.processor;
  74.       }
  75.       return "Test In Process.";
  76.    }
  77. }
  78.