Author Topic: effective way to speed test?  (Read 7031 times)

0 Members and 1 Guest are viewing this topic.

Offline blackwings

  • Scripter
  • King
  • ******
  • Posts: 986
  • Karma: +12/-8
effective way to speed test?
« 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 =
Code: [Select]
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.


PtokaX forum

effective way to speed test?
« on: 22 June, 2005, 15:01:14 »

Offline Dessamator

  • Scripter
  • Emperor
  • ******
  • Posts: 1 262
  • Karma: +13/-9
(No subject)
« Reply #1 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 :)
Ignorance is Bliss.

Offline blackwings

  • Scripter
  • King
  • ******
  • Posts: 986
  • Karma: +12/-8
(No subject)
« Reply #2 on: 22 June, 2005, 15:55:35 »
Quote
Originally 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.


Offline Dessamator

  • Scripter
  • Emperor
  • ******
  • Posts: 1 262
  • Karma: +13/-9
(No subject)
« Reply #3 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 :

Code: [Select]
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
Ignorance is Bliss.

Offline blackwings

  • Scripter
  • King
  • ******
  • Posts: 986
  • Karma: +12/-8
(No subject)
« Reply #4 on: 23 June, 2005, 15:03:09 »
Quote
Originally 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 :

Code: [Select]
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


Offline blackwings

  • Scripter
  • King
  • ******
  • Posts: 986
  • Karma: +12/-8
(No subject)
« Reply #5 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.


Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 730
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #6 on: 23 June, 2005, 19:17:55 »
local x=os.clock()
-- code here
SendToAll(os.clock()-x)
Everything could have been anything else and it would have just as much meaning.

Offline blackwings

  • Scripter
  • King
  • ******
  • Posts: 986
  • Karma: +12/-8
(No subject)
« Reply #7 on: 23 June, 2005, 19:31:48 »
Quote
Originally 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().
« Last Edit: 23 June, 2005, 19:35:39 by blackwings »


Offline Typhoon

  • Lord
  • ***
  • Posts: 397
  • Karma: +22/-3
  • PGE Developer
    • PGE Homepage
(No subject)
« Reply #8 on: 23 June, 2005, 19:46:23 »
this one works just fine :)

Code: [Select]

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?



Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 730
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #9 on: 23 June, 2005, 20:35:59 »
Quote
Originally posted by blackwings
Quote
Originally 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"?
Everything could have been anything else and it would have just as much meaning.

Offline blackwings

  • Scripter
  • King
  • ******
  • Posts: 986
  • Karma: +12/-8
(No subject)
« Reply #10 on: 23 June, 2005, 21:03:31 »
Quote
Originally posted by bastya_elvtars
What do you mean by "not work"?
I get 0.0000 seconds :P


Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 730
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #11 on: 23 June, 2005, 21:14:55 »
Quote
Originally posted by blackwings
Quote
Originally 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:

Code: [Select]
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)
Everything could have been anything else and it would have just as much meaning.

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #12 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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 730
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #13 on: 23 June, 2005, 22:05:00 »
Quote
Originally 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
Everything could have been anything else and it would have just as much meaning.

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #14 on: 23 June, 2005, 22:56:09 »
Quote
Originally posted by bastya_elvtars
Quote
Originally 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).
Code: [Select]
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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Offline VidFamne

  • Triple Ace
  • **
  • Posts: 173
  • Karma: +2/-0
(No subject)
« Reply #15 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.
« Last Edit: 25 June, 2005, 15:22:24 by VidFamne »

Offline Dessamator

  • Scripter
  • Emperor
  • ******
  • Posts: 1 262
  • Karma: +13/-9
(No subject)
« Reply #16 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 !
Ignorance is Bliss.

Offline VidFamne

  • Triple Ace
  • **
  • Posts: 173
  • Karma: +2/-0
(No subject)
« Reply #17 on: 25 June, 2005, 16:57:37 »
I'd suggest some thing like this;
Quote
local 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. ")

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #18 on: 25 June, 2005, 21:11:01 »
Quote
Originally 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 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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Offline blackwings

  • Scripter
  • King
  • ******
  • Posts: 986
  • Karma: +12/-8
(No subject)
« Reply #19 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?

Code: [Select]
local x=os.clock()
for k=0,1500 do
-- code here
end
itotal = (os.clock()-x)
SendToAll(Bot, string.format( "%.4f", itotal ))
« Last Edit: 17 July, 2005, 19:03:26 by blackwings »


Offline blackwings

  • Scripter
  • King
  • ******
  • Posts: 986
  • Karma: +12/-8
(No subject)
« Reply #20 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
« Last Edit: 18 July, 2005, 22:03:35 by blackwings »


Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #21 on: 18 July, 2005, 18:30:54 »
Quote
Originally 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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Offline blackwings

  • Scripter
  • King
  • ******
  • Posts: 986
  • Karma: +12/-8
(No subject)
« Reply #22 on: 18 July, 2005, 19:32:05 »
Quote
Originally 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 =
Code: [Select]
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 =
Quote
Originally 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)


Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #23 on: 18 July, 2005, 23:35:31 »
Quote
Originally 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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Offline blackwings

  • Scripter
  • King
  • ******
  • Posts: 986
  • Karma: +12/-8
(No subject)
« Reply #24 on: 19 July, 2005, 21:01:53 »
Quote
Originally posted by plop
Quote
Originally 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 :) ) =
  • local functions
  • if's that are connected to a function,
  • reloops of the function,
  • various way to use if's/for
  • etc


PtokaX forum

(No subject)
« Reply #24 on: 19 July, 2005, 21:01:53 »