Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   GBench (https://forums.graalonline.com/forums/showthread.php?t=134258366)

WhiteDragon 03-13-2010 03:03 AM

GBench
 
5 Attachment(s)
Benchmarking!
If you have ever found yourself trying to make a script run faster, it can be a pain. GBench (a benchmarker) makes it less of a pain:
  1. You create a function you want to benchmark
  2. You join("utility_benchmark");
  3. You call this.defaultMain({this.bench("someName", temp.yourFunctionHere)});

It will run 100 samples (basically a sample is enough of your function calls to take up at least 0.01 secs).

Then it will give you a histogram that shows each sample and how long it took.

And then it will give you something called a "Kernel Density Estimation". That is a statistics term for a pretty simple concept:
In our case, look at any point on the kernel density estimate, and that is your probability of your function taking that long.



Example!
PHP Code:

this.join("utility_benchmark");
//#CLIENTSIDE

// some example function you wrote
function fib(temp.n) {
  if (
temp.== 0) {
    return 
0;
  }
  if (
temp.== 1) {
    return 
1;
  }
  return 
fib(temp.n-1) + fib(temp.n-2);
}

// just in case
function onCreated() {
  
this.maxlooplimit 20000;
}


function 
onWeaponFired() {
  
// this is what we will be testing
  
temp.= function () {
    return 
this.fib(18);
  };

  
// let's go!
  
this.defaultMain({
    
this.bench("fib"temp.f)
  });


In your F2, you will get:
NPC Code:
benchmarking fib 
collecting 100 samples, 1 iterations each, in estimated 4.057331309 s
mean: 41.656855829 ms, lb: 41.109135379 ms, ub: 42.937021324 ms



And, then you will get your histogram and kernel density estimate (all times are in milliseconds):
http://forums.graalonline.com/forums...4&d=1268441055

The big hill on the kernel density estimate shows that most likely the function will take around 41.6 ms to run. The smaller hill near the end means there is a slight chance that the function will take 43 ms to run.



Known Bugs :(
  • On some computers, in v5, some samples take a negative amount of time to run. I have no clue why this would happen, since it just compares timevar2s.
  • In v6, division doesn't work nicely and can make the graph axis a bit hard to read.



The magic is attached!

fowlplay4 03-13-2010 03:13 AM

Neat graphs.

adam 03-13-2010 03:42 AM

Pretty.

DustyPorViva 03-13-2010 05:12 AM

How did you accomplish the AA? O.o

WhiteDragon 03-13-2010 06:00 AM

Quote:

Originally Posted by DustyPorViva (Post 1562171)
How did you accomplish the AA? O.o

Haha, I didn't, that was just the save on the file that messed with it.

Crow 03-13-2010 10:41 AM

I'd rep you, but I have to spread some rep first. Very nice!

xAndrewx 03-13-2010 02:56 PM

Good Job :)


All times are GMT +2. The time now is 01:52 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.