Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-13-2010, 03:03 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
GBench

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):


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!
Attached Thumbnails
Click image for larger version

Name:	benchmarks.gif
Views:	667
Size:	22.5 KB
ID:	50554  
Attached Files
File Type: txt algorithm_quicksort.txt (1.9 KB, 286 views)
File Type: txt utility_benchmark.txt (2.6 KB, 294 views)
File Type: txt utility_graph.txt (4.3 KB, 327 views)
File Type: txt utility_statistics.txt (4.4 KB, 288 views)

Last edited by WhiteDragon; 03-13-2010 at 03:16 AM..
Reply With Quote
  #2  
Old 03-13-2010, 03:13 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Neat graphs.
__________________
Quote:
Reply With Quote
  #3  
Old 03-13-2010, 03:42 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura about
Send a message via AIM to adam
Pretty.
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
  #4  
Old 03-13-2010, 05:12 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
How did you accomplish the AA? O.o
Reply With Quote
  #5  
Old 03-13-2010, 06:00 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by DustyPorViva View Post
How did you accomplish the AA? O.o
Haha, I didn't, that was just the save on the file that messed with it.
Reply With Quote
  #6  
Old 03-13-2010, 10:41 AM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
I'd rep you, but I have to spread some rep first. Very nice!
__________________
Reply With Quote
  #7  
Old 03-13-2010, 02:56 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Good Job
__________________
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:27 AM.


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