Welcome Guest ( Log In | Register )

[ Big| Medium| Small] -



Post new topic Reply to topic  [ 5 posts ] 
    zeus81
  Fri Oct 14, 2011 1:34 am
prout
User avatar
Member


Location: France
Performance Counter
(script for scripterz)


Introduction
This script is useful to mesure little bits of time, more little than with Time class.
You can use it to check if your script is slow and find from which part it comes, or to compare scripts performances.
(I love performance. :fap:)


Script

Expand to see the code.


Instructions
First create a counter :
$pc = PerformanceCounter.new

Then place the tags on both sides of what you want to mesure, like this :
$pc.a
do_something
$pc.b

Or by using a block like that :
$pc.c {do_something}

The counter is a Sprite (so you can place it where you want with x and y methods) and is automaticaly refreshed, you just have to place the tags.
You can choose the way the time is displayed and at what rate it's refreshed on the initialization :
$pc = PerformanceCounter.new(display_type, refresh_rate)

Or after by using the accessors :
$pc.display_type = x
$pc.refresh_rate = y

There are 5 differents display_type : 0 = number of ticks*, 1 = nanoseconds, 2 = microseconds, 3 = milliseconds and 4 = seconds (default is 0).
For the refresh_rate it's a number of frames, but if you set it to 0 it will only keep the lowest value, if you have a code that is not dynamic it may give a result nearest of the reality (default is 1).
And if you want you can get the last time in ticks*, nanoseconds, etc... with $pc.t, $pc.ns, $pc.us, $pc.ms or $pc.s


*Or cycles perhaps ? I'm not sure, it's an unit which is processor relative but too high I think to be one of this kind.
On my PhenomII X4 4Ghz, 1 unit is equal to 255 ns. :(

_________________
>> The Ark of Gladoria <<


Last edited by zeus81 on Fri Oct 14, 2011 6:03 am, edited 1 time in total.

Top Top
Profile      
 

    ForeverZer0
  Fri Oct 14, 2011 3:39 am
ARC Developer
User avatar
Sponsor


Location: United tates
The performance encounter itself consumes a bit too much resources to keep things accurate.

Although anything is going to use some resources, something that is used to benchmark speed should be as low impact as possible. I've personally really only tested methods, calls, with the Console Debug script I wrote.

At the beginning of the method, place a "start = Time.now.to_f" and at the end place a "puts (Time.now.to_f - start)"
This will output the time the call took to execute, and of course you can edit it a bit to output averages, etc.

_________________
Use DropBox to upload your files. Much simpler than other upload sites, you can simply place a folder on your desktop that will sync with your DropBox account. ;)

Looking for a more powerful RMXP? Check out Image

My complete script list on Pastebin


Top Top
Profile      
 

    Kingdom Ablaze
  Fri Oct 14, 2011 4:15 am
Smile, you never know when you are on camera!
User avatar



Location: Usa
im with foreverzer0 i always just use

time=Time.now
my code
p Time.now-time

but im glad im not the only one that likes to measure the speed of my code :D

_________________
Image
Kingdom Ablaze Twitter: https://twitter.com/KingdomAblaze
Kingdom Ablaze Deviant Art: http://kingdomablaze.deviantart.com/
Kingdom Ablaze: Facebook: https://www.facebook.com/KingdomAblazeTradingCardGame


Top Top
Profile      
 

    zeus81
  Fri Oct 14, 2011 6:01 am
prout
User avatar
Member


Location: France
If you look at the code you'll see that between the markers there is nothing except the call of the Api which pick the time, the refresh of the bitmap is done after #b so it doesn't impact the time at all.
The call to the Api is quite fast (1.2 µs), but if it can make you happy I edited the script to remove it (even if it's not perfect).
And why not use Time.now ? Well in RM we use Ruby 1.8.1 and its Time class can't go under milliseconds.
So it avoid doing :
time=Time.now
10000.times {my code}
p Time.now-time

But the most interesting in this script I think is that you can use it with ease and all is displayed on the flow. :)

_________________
>> The Ark of Gladoria <<


Top Top
Profile      
 

    Kingdom Ablaze
  Fri Oct 14, 2011 2:35 pm
Smile, you never know when you are on camera!
User avatar



Location: Usa
i dont think you need to go that deep with ruby, but thats just a personal opinion, i only go super deep with my c# programs, because i might actually be able to make them run fast :P silly slow ruby :) but i do see your point, to each their own.

_________________
Image
Kingdom Ablaze Twitter: https://twitter.com/KingdomAblaze
Kingdom Ablaze Deviant Art: http://kingdomablaze.deviantart.com/
Kingdom Ablaze: Facebook: https://www.facebook.com/KingdomAblazeTradingCardGame


Top Top
Profile      
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 


Who is online

Users browsing this forum: No users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

We are an independent, not-for-profit game making community.
Homepage
Board Index
About Us
Downloadable Games
Free Browser Games
Games in Development
RPG Maker Support
Game Maker Support
Construct 2 Support
HBGames the eZine
Advanced RPG Maker
Site Announcements
Powered by phpBB © phpBB Group