PtokaX forum

Development Section => Your Developing Problems => Topic started by: blackwings on 22 June, 2005, 15:01:14

Title: effective way to speed test?
Post by: blackwings on 22 June, 2005, 15:01:14
I wonder if there is some kind of way to speed test your code by adding code that
speed test it or if there are other ways to speed test the code. I have tried the way chilla speed tested a script = local itotal = 0
local t1 = os.clock()
-- the code that is going to be speedtested
local t2 = os.clock()
itotal = itotal + (t2-t1)
SendToAll( "Speed:"..string.format( "%.4f", itotal ).." seconds. ")
but it didn't work, it gave me 0.0000 seconds, which is impossible for a script to get such result.
Title:
Post by: Dessamator on 22 June, 2005, 15:52:17
well, in theory it might have taken 0.000002 seconds, due to ur formating, it might not show :)
Title:
Post by: blackwings on 22 June, 2005, 15:55:35
QuoteOriginally posted by Dessamator
well, in theory it might have taken 0.000002 seconds, due to ur formating, it might not show :)
well, the thing is, is there a way to make a working speed test, because chillas speed test doesn't work.
Title:
Post by: Dessamator on 22 June, 2005, 17:23:09
it does work, the thing is it might take milliseconds for a the program to execute just to prove my theory , try this :

function Main()

local itotal = 0
local t1 = os.clock()
--
for i=1,1000000 do
if i==1000000 then
t2 = os.clock()
end
end
itotal = (t2-t1)
SendToAll( "Speed:"..string.format( "%.4f", itotal ).." seconds. ")
end
Title:
Post by: blackwings on 23 June, 2005, 15:03:09
QuoteOriginally posted by Dessamator
it does work, the thing is it might take milliseconds for a the program to execute just to prove my theory , try this :

function Main()

local itotal = 0
local t1 = os.clock()
--
for i=1,1000000 do
if i==1000000 then
t2 = os.clock()
end
end
itotal = (t2-t1)
SendToAll( "Speed:"..string.format( "%.4f", itotal ).." seconds. " )
end
it seems to be working, but I need to make more testing to be sure :P
Title:
Post by: blackwings on 23 June, 2005, 19:16:32
ok, the speed test doesn't work. it only take time on your for/if. it seems to ignore all other code it runs.
Title:
Post by: bastya_elvtars on 23 June, 2005, 19:17:55
local x=os.clock()
-- code here
SendToAll(os.clock()-x)
Title:
Post by: blackwings on 23 June, 2005, 19:31:48
QuoteOriginally posted by bastya_elvtars
local x=os.clock()
-- code here
SendToAll(os.clock()-x)
doesn't work either :(

I think the problem is that it does this =
SendToAll(current os.clock()-current os.clock()) which is = 0

and not this =
SendToAll(14:37:11-14:37:10) which is = 1

Its possible that x doesn't keep the value of os.clock().
Title:
Post by: Typhoon on 23 June, 2005, 19:46:23
this one works just fine :)


Main = function()
local x = os.clock()
local file = io.open("UserInfo.ini","a+")
for i = 0, 500 do
--,nick,ip,seen,profile,myinfo
file:write("']['yphoon?"..i.."|127.0.0.1|12/01/2003 - 15:43|-1|%$MyINFO %$ALL tyffe"..i.." 2048/256<++ V:0.670,M:A,H:77/0/0,S:6>%$ %$DSL%$%$201474669430%$\n")
end
file:close()
SendToAll("Time wasted was "..os.clock()-x.." seconds.")
end


enjoy :)

Typhoon?
Title:
Post by: bastya_elvtars on 23 June, 2005, 20:35:59
QuoteOriginally posted by blackwings
QuoteOriginally posted by bastya_elvtars
local x=os.clock()
-- code here
SendToAll(os.clock()-x)
doesn't work either :(

I think the problem is that it does this =
SendToAll(current os.clock()-current os.clock()) which is = 0

and not this =
SendToAll(14:37:11-14:37:10) which is = 1

Its possible that x doesn't keep the value of os.clock().

What do you mean by "not work"?
Title:
Post by: blackwings on 23 June, 2005, 21:03:31
QuoteOriginally posted by bastya_elvtars
What do you mean by "not work"?
I get 0.0000 seconds :P
Title:
Post by: bastya_elvtars on 23 June, 2005, 21:14:55
QuoteOriginally posted by blackwings
QuoteOriginally posted by bastya_elvtars
What do you mean by "not work"?
I get 0.0000 seconds :P

Then try the following:

Create a folder inside scripts. Call it test.

Now do the following:

local x=os.clock()
local f=io.open("test/testfile")
for 0,1500 do
f:write([[Amaury Amblard-Ladurantie rewrote this website to be compliant with W3C standards. Thanks to him, the website is now more accessible, and more robust. You may want to visit W3C's website if you want to learn more about the importance of standard browsing.

You can notice that the image on the mainpage has been updated, and now includes a teaser with a screenshot of the upcoming network version. Now let's hope this pushes us to the release, for real this time.

Ah - and I forgot to tell: Frozen-Bubble won Linux Journal 2004 Readers' Choice Awards last year (but unavailability of the article on the web made me choose not to write a news item about it). ]])
end
f:close()
print(os.clock()-x)
Title:
Post by: plop on 23 June, 2005, 21:49:41
LUA is 1 of the fastest scripting languages, and many parts are actualy done in c.
and unlike most scripting languages, lua compiles every script before executing it.
for example file:read("*all") is fully handled in c.
getting 0.00000 is pretty normal.

if you wanna do some real preformance testing you need the lua command line and process the same function 1000-5000 times.

plop
Title:
Post by: bastya_elvtars on 23 June, 2005, 22:05:00
QuoteOriginally posted by plop
getting 0.00000 is pretty normal.

if you wanna do some real preformance testing you need the lua command line and process the same function 1000-5000 times.

That's why I posted him the script that writes the latest news from frozen-bubble.org 1500 times to a file. :P
Title:
Post by: plop on 23 June, 2005, 22:56:09
QuoteOriginally posted by bastya_elvtars
QuoteOriginally posted by plop
getting 0.00000 is pretty normal.

if you wanna do some real preformance testing you need the lua command line and process the same function 1000-5000 times.

That's why I posted him the script that writes the latest news from frozen-bubble.org 1500 times to a file. :P

perfect way.

got a nice 1 here which i made in the past (execute on the lua 4 command line).
nMyInfo = "$MyINFO $ALL mspp  <++ V:0.306,M:P,H:1/0/0,S:3>$ $Cable$$46472917385$|"
amount =1000000

local x = clock()
for i=1,amount do
   local s,e,Descr,Speed,Email,Share = strfind(nMyInfo, "^%$MyINFO $ALL [^ ]+ ([^$]+)$ $([^$]*)$([^$]*)$([^$]+)")
   Speed = strsub(Speed,1,strlen(Speed)-1)
end
print(clock()-x)
print(Speed)

x=clock()
for i=1,amount do
   local s,e,Descr,Speed,Email,Share = strfind(nMyInfo, "^%$MyINFO $ALL [^ ]+ ([^$]+)$ $([%d%w]*)[^$]*$([^$]*)$([^$]+)")
end
print(clock()-x)
print(Speed)

plop
Title:
Post by: VidFamne on 25 June, 2005, 15:19:19
Isn't all locals in a function evaluated first, before the function is executed?
If so the t1 and t2 got the same value.
Title:
Post by: Dessamator on 25 June, 2005, 15:51:05
hmm, its possible , if ur right, then it will always be the same no matter how much code there is , or how much time it takes to execute !
Title:
Post by: VidFamne on 25 June, 2005, 16:57:37
I'd suggest some thing like this;
Quotelocal itotal = 0
local t1 = os.clock()
-- the code that is going to be speedtested
--local t2 = os.clock()
itotal = os.clock()-t1
SendToAll( "Speed:"..string.format( "%.4f", itotal ).." seconds. ")
Title:
Post by: plop on 25 June, 2005, 21:11:01
QuoteOriginally posted by VidFamne
Isn't all locals in a function evaluated first, before the function is executed?
If so the t1 and t2 got the same value.

nope, lua is a kind of character interpred language.
alltho lua precompiles before executing (this moment the syntax errors show up).
lua makes the locals the moment the script declares them and drops them the moment they aren't needed anymore.
check here (http://board.univ-angers.fr/thread.php?threadid=4813&boardid=4&styleid=1) for more info.

but your suggestion 2 drop t2 is really good, saves 1 more local (basicly it's a local, but with a even shorter lifetime).

plop
Title:
Post by: blackwings on 17 July, 2005, 16:04:34
Is it possible, for all the ways you can code something, that the speedtest can give a wrong result, like way to fast result?

local x=os.clock()
for k=0,1500 do
-- code here
end
itotal = (os.clock()-x)
SendToAll(Bot, string.format( "%.4f", itotal ))
Title:
Post by: blackwings on 17 July, 2005, 21:25:59
My question in my last post before this one, I wasn't asking about a different way to speed test nor did I have the 0.0000 problem :P

What I was asking was if the speed test could show a incorrect result, like way to fast/good result,
depending on what way the code you are speed testing is coded like (you know, local functions, if's that are connected to a function, reloops of the function etc)

Just wondering this because I made a change to a script that now makes an older code faster, which earlier was proven to be slower.
Now after the change in the script, the older code is now faster than the newer code :S
Title:
Post by: plop on 18 July, 2005, 18:30:54
QuoteOriginally posted by blackwings
My question in my last post before this one, I wasn't asking about a different way to speed test nor did I have the 0.0000 problem :P

What I was asking was if the speed test could show a incorrect result, like way to fast/good result,
depending on what way the code you are speed testing is coded like (you know, local functions, if's that are connected to a function, reloops of the function etc)

Just wondering this because I made a change to a script that now makes an older code faster, which earlier was proven to be slower.
Now after the change in the script, the older code is now faster than the newer code :S

maby you made an error on the speedtesting code.
or the delay comes from another place.
maby you can post both pieces of code so other ppl can do the same test.

plop
Title:
Post by: blackwings on 18 July, 2005, 19:32:05
QuoteOriginally posted by plop maby you made an error on the speedtesting code.
or the delay comes from another place.
maby you can post both pieces of code so other ppl can do the same test.

plop
this is my speed test code = local x=os.clock()
for k=0,1500 do
-- put code that is going to be tested here
end
itotal = (os.clock()-x)
SendToAll(Bot, string.format( "%.4f", itotal ))
anyway, I didn't mean the speed test code with this, I meant the code that is tested within the speed test code =
QuoteOriginally posted by blackwings
What I was asking was if the speed test could show a incorrect result, like way to fast/good result,
depending on what way the code you are speed testing is coded like (you know, local functions, if's that are connected to a function, reloops of the function,
various way to use ifs/for etc)
Title:
Post by: plop on 18 July, 2005, 23:35:31
QuoteOriginally posted by blackwings
anyway, I didn't mean the speed test code with this, I meant the code that is tested within the speed test code =

i ment that code 2, the part you wanted 2 measure.

plop
Title:
Post by: blackwings on 19 July, 2005, 21:01:53
QuoteOriginally posted by plop
QuoteOriginally posted by blackwings
anyway, I didn't mean the speed test code with this, I meant the code that is tested within the speed test code =

i ment that code 2, the part you wanted 2 measure.

plop
Can't give you the code,sorry :(. Its from my anti-advertise which I release as compiled in the forum :baby:  

But my code works correctly(I have extensively tested it :] ), so there is no bug that causes the very good result :).

So with your wide knowledge of lua, can't you give it a try and think about anything in lua, which maybe does give way to good/fast result,
like speedtest on (not correct names, but I hope you understand what I mean :) ) =