[Include] Benchmark include
#1

Benchmark include

Introduction
This include allows the possibility to perform stress tests against specially initialized functions (called benchmarks). You can easily initialize these benchmarks without having to write out loops and compare the results all of the time.

How does it work?
It's simple, download the latest version of YSI here and include it at the top of the script:

pawn Код:
#include <benchmarks>
After that, you can initialize your own benchmarks:

pawn Код:
Benchmark:name[time]() {}
Please note that these functions can't return values, as it would be very redundant if they could do so anyway.

Initializing benchmarks
Using the example above, you can initialize benchmarks easily:

pawn Код:
Benchmark:test[1000]()
{
    // Code here...
}
1000 is the number of times to call the corresponding code. You can also specify parameters!

pawn Код:
Benchmark:test[1000](string[128])
{
    // Code here...
}
Performing benchmarks
There are two functions that allows you to perform these benchmarks.

pawn Код:
forward Benchmark_Run(...);
Passing no arguments will run all benchmark functions. You can also pass only the ones you wish to test:

pawn Код:
Benchmark_Run("test", "test2");
You can also use "Benchmark_RunEx" which allows you to run a benchmark with a custom set time:

pawn Код:
// This would run test 10,000 times instead of the defined 1,000.
Benchmark_RunEx("test", 10000);
It can also accept multiple parameters.

pawn Код:
Benchmark_RunEx("test", 10000, "test2", 20000);
OnBenchPerformed
This include also adds a new special callback:

pawn Код:
public OnBenchPerformed(function[], time)
{
    return 1;
}
This callback is called once a benchmark has completed.

Credits
  • ****** - Inspired by y_timers and y_testing.
  • Slice - Inspired by his benchmark macros.
Download
Available at my GitHub page - click here.

The reason I use GitHub now is because it allows me to control my libraries easier and quicker, without having to always delete and upload files.
Reply


Messages In This Thread
Benchmark include - by Emmet_ - 02.01.2014, 18:36
Re: Benchmark include - by PT - 03.01.2014, 06:57
Re: Benchmark include - by Emmet_ - 03.01.2014, 07:06
Re: Benchmark include - by GiamPy. - 03.01.2014, 12:00
Re: Benchmark include - by Emmet_ - 03.01.2014, 12:13
Re: Benchmark include - by iZN - 04.01.2014, 06:38

Forum Jump:


Users browsing this thread: 1 Guest(s)