effective way to speed test?
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

effective way to speed test?

Started by blackwings, 22 June, 2005, 15:01:14

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

blackwings

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.


Dessamator

well, in theory it might have taken 0.000002 seconds, due to ur formating, it might not show :)
Ignorance is Bliss.

blackwings

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.


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
Ignorance is Bliss.

blackwings

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


blackwings

ok, the speed test doesn't work. it only take time on your for/if. it seems to ignore all other code it runs.


bastya_elvtars

local x=os.clock()
-- code here
SendToAll(os.clock()-x)
Everything could have been anything else and it would have just as much meaning.

blackwings

#7
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().


Typhoon

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?



bastya_elvtars

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"?
Everything could have been anything else and it would have just as much meaning.

blackwings

QuoteOriginally posted by bastya_elvtars
What do you mean by "not work"?
I get 0.0000 seconds :P


bastya_elvtars

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

plop

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

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
Everything could have been anything else and it would have just as much meaning.

plop

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

VidFamne

#15
Isn't all locals in a function evaluated first, before the function is executed?
If so the t1 and t2 got the same value.

Dessamator

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.

VidFamne

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. ")

plop

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

blackwings

#19
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 ))


blackwings

#20
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


plop

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

blackwings

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)


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

blackwings

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 :) ) =
  • local functions
  • if's that are connected to a function,
  • reloops of the function,
  • various way to use if's/for
  • etc


SMF spam blocked by CleanTalk