[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
#2

IpsBruno has did something like that..

look

Quote:
Originally Posted by ipsBruno
Посмотреть сообщение
pawn Код:
#define CONT@CONT GetTickCount()


#define TESTS(%0);          { /*esquentar o processador */ for(new uashushua; uashushua != 9990000; uashushua++) {} /* testar o cуdigo */  new testes___@ [666], mMmEDIA;  new j__@; new TTTiem =   CONT@CONT;  for(new i__@; i__@ != 333; ++i__@ ) { j__@=0;testes___@[i__@] = CONT@CONT;for(; j__@ != %0; ++j__@ ) {
#define PROCESSAR();        }testes___@[i__@] = CONT@CONT - testes___@[i__@];mMmEDIA += testes___@[i__@];}mMmEDIA /= (333);new mmMin = cellmax, mMax = 0;for(new aaa_@_teste; aaa_@_teste != 666; aaa_@_teste++) {
#define RESULTADO(%0);      if(mmMin > testes___@[aaa_@_teste]) mmMin = testes___@[aaa_@_teste]; if(mMax < testes___@[aaa_@_teste]) mMax = testes___@[aaa_@_teste];}printf("Resultados para: "#%0" \n\t\n\t Nъmeros de execuзгo a cada milissegundo: %.5f \n\t Tempo mнnimo: %dms  Tempo mбximo: %dms e Tempo mйdio: %dms\n\t Tempo Final: %d milissegundos\n\n",  float((j__@) / (mMmEDIA > 0 ? mMmEDIA : 1))/1000,mmMin, mMax,mMmEDIA,  CONT@CONT - TTTiem);}
and you use like this:
Quote:
Originally Posted by ipsBruno
Посмотреть сообщение
pawn Код:
//

TESTS(333);
// O CУDIGO VAI AQUI
PROCESSAR();
RESULTADO("Nome do cуdigo");
Original Topic: https://sampforum.blast.hk/showthread.php?tid=469273



Nice work Emmet.
Reply
#3

Thanks.

However, this is completely different from macros, as this allows you to specially initialize callbacks and call the benchmarks that you wish to run.
Reply
#4

What would think about tracking the time between each tick?

Even though it would be kinda heavy it will allow you to do some cool statistics (ie. average ms between each tick, which phase of the benchmark was faster, etc).
Reply
#5

That's a great idea, it would definitely make benchmarks more thorough and evident.

I was thinking of:

pawn Код:
Benchmark:bench1[100000]()
{
}

main()
{
    new
        average,
        fastest,
        slowest;
 
    Benchmark_Execute("bench1", average, fastest, slowest);

    printf("Average time between each tick: %d ms", average);
    printf("Fastest phase: %d ms", fastest);
    printf("Slowest phase: %d ms", slowest);
}
Though there will be more than those 3.
Reply
#6

Nice work Emmet.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)