Use Julia set to test computer performance

Source: Internet
Author: User
Tags time limit


I haven't been here for a long time. This time I will bring you some things.

As we all know, the Julia set is an iterative algorithm, that is, the results are constantly put into algorithm computing, so that the results are constantly approaching the real value.

For example, we use this algorithm for calculation & pi; and e.

The Julia set has many forms that consume a large amount of resources to produce results. We can use this algorithm to test computer performance.

Because BitmapData is supported, use FlashPlayer8.0 for playback.

/**
ActionScript Source File -- Created with SAPIEN Technologies PrimalScript 3.1
  
@ Class Test.
@ Package
@ Author tcper@163.com Loki_tang
@ Codehint
@ Example: import Test;
Var someObject: Test = new Test;
SomeObject. tester (. 01 );
@ Tooltip
*/
Import flash. display. BitmapData;
Class Test extends MovieClip {
Private var n: Number;
Private var cx: Number;
Private var cy: Number;
Private var x2: Number;
Private var y2: Number;
Private var rgb: Number;
Private var timeGot: Number;
Private var rgbOffset: Number;
Private var pixelPos: Number;
Private var mc: MovieClip;
Private var mcOrigin: MovieClip;
Private var myBitmapData: BitmapData;
// A and B are parameters of the Julia set.
Private static var a: Number =. 5;
Private static var B: Number =. 55;
Private static var pixelNum: Number = 0;
Private static var timeLimitation: Number = 4000; // computing time limit
Function Test (){
BitmapCreator ();
 }
Private function bitmapCreator (): BitmapData {
MyBitmapData = new BitmapData (400,400, false, 0 xcccccccc );
Return myBitmapData;
 }
Private function mcCreator (): MovieClip {
McOrigin = this. createEmptyMovieClip ("mc", this. getNextHighestDepth ());
Return mcOrigin;
 }
Private function getRGB (I: Number, u: Number): Number {
Rgb = (I-u) * 200;
Return rgb;
 }
Private function getPixelPos (I: Number): Number {
PixelPos = Math. floor (I + 1.5) * 133.3 );
Return pixelPos;
 }
Private function timeCheck (I: Number): Boolean {
If (getTimer ()-I) return true;
} Else {
Return false;
  }
 }
// Public Method;
Public static function pixelStatistic (): Number {
Return pixelNum;
 }
Public function tester (u: Number): Void {
RgbOffset = Math. floor (100 * Math. random ());
TimeGot = getTimer ();
Var mc = mcCreator ();
Mc. attachBitmap (bitmapCreator (), this. getNextHighestDepth ());
Mc. _ x = mc. _ y =-200;
// The following is the Julia algorithm.
For (var I =-1.5; I <= 1.5; I + = u ){
For (var j =-1.5; j <= 1.5; j + = u ){
Cx = I;
Cy = j;
For (var n = 1; n <= 100; n ++ ){
PixelNum ++;
X2 = cx * cx-cy * cy +;
Y2 = 2 * cy * cx + B;
Cx = x2;
Cy = y2;
If (cx * cx + cy * cy> 4 ){
Break;
     }
If (! TimeCheck (timeGot )){
Return;
     }
    }
BitmapCreator (). setPixel (getPixelPos (I), getPixelPos (j), getRGB (n, rgbOffset ));
   }
  }
 }
}
 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.