perftest2.jc

来自「The JILRunOnly project is a simple comma」· JC 代码 · 共 50 行

JC
50
字号

/*
 *	perftest2.jc
 *
 *	A simple performance test. Count repeatedly from 0 to 1.000.000 and take average time.
 */

// Import Typelibs

import stdlib;

// number of iterations the script will do
const long kNumIterations = 100;

// time to sleep between iterations (to avoid heat)
const long kSleepTimeMillisec = 200;

/*
 *	function main
 */

function string main()
{
    long i;
    long j;
    long startTime;
    long duration;
    float durationF = 0;
    float iters = 1;
    string message;

    stdlib::Print("A simple performance test. Count repeatedly from 0 to 1.000.000 and take average time.\n");

	for( j = 0; j < kNumIterations; j++ )
	{
		startTime = stdlib::GetTicks();

		for( i = 0; i < 1000000; i++ )
			/*Empty statement*/;

		duration = stdlib::GetTicks() - startTime;
		durationF += duration;
		stdlib::Printf("Iteration #%g: Time = %d ms (Average time = %g ms)\n", {iters, duration, durationF / iters} );
		stdlib::Sleep(kSleepTimeMillisec);	// wait a little... be nice to your CPU ;)
		iters++;
	}

	return "Done.";
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?