| View previous topic :: View next topic |
| Author |
Message |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Mon Apr 04, 2005 2:41 pm Post subject: Executing time - How to improve your code's speed? |
|
|
I just created the script below to test which is faster: a lot of functions on the same line, or the same amount of functions spreaded over multiply lines, to see how to create your program so that it works as fast as possible. Over here, the "longline" test is much faster then the "spreaded", about 20%. Maybe it's something to think about when programming?
| Code: | #define function,test1,test2
DIALOG CREATE,Nieuw Dialoog,-1,0,432,334
REM *** Gewijzigd door de Dialoog Ontwerper op 4-4-2005 - 16:25 ***
DIALOG ADD,LIST,LIST1,3,5,420,327
DIALOG SHOW
rem You can change these values:
%%loops = 50000
%%repeat = 5
rem Code starting here:
%%test1 = 0
%%test2 = 0
%%originalrepeat = %%repeat
repeat
list add,list1,---------------------------------------------------------------
%%temp = @test1()
%%test1 = @sum(%%test1,%%temp)
list add,list1,Longline: @tab()%%temp seconds
%%temp = @test2()
%%test2 = @sum(%%test2,%%temp)
list add,list1,Spreaded: @tab()%%temp seconds
%%repeat = @pred(%%repeat)
until @equal(%%repeat,0)
list add,list1,---------------------------------------------------------------
list add,list1,Done...
list add,list1,---------------------------------------------------------------
list add,list1,Average longline: @fdiv(%%test1,%%originalrepeat)
list add,list1,Average spreaded: @fdiv(%%test2,%%originalrepeat)
:Evloop
wait event
goto @event()
:Close
exit
:test1
%x = 0
%%begin = @sum(@prod(@datetime(hh),3600),@prod(@datetime(nn),60),@datetime(ss))
repeat
%p = @succ(@succ(@succ(@succ(@succ(@succ(@succ(@succ(@succ(@succ(@succ(@succ(@succ(@succ(@succ(@succ(@succ(@succ(@succ(0)))))))))))))))))))
%x = @succ(%x)
until @equal(%x,%%loops)
%%end = @sum(@prod(@datetime(hh),3600),@prod(@datetime(nn),60),@datetime(ss))
exit @diff(%%end,%%begin)
:test2
%x = 0
%%begin = @sum(@prod(@datetime(hh),3600),@prod(@datetime(nn),60),@datetime(ss))
repeat
%p = @succ(0)
%p = @succ(0)
%p = @succ(0)
%p = @succ(0)
%p = @succ(0)
%p = @succ(0)
%p = @succ(0)
%p = @succ(0)
%p = @succ(0)
%p = @succ(0)
%p = @succ(0)
%p = @succ(0)
%p = @succ(0)
%p = @succ(0)
%p = @succ(0)
%p = @succ(0)
%p = @succ(0)
%p = @succ(0)
%x = @succ(%x)
until @equal(%x,%%loops)
%%end = @sum(@prod(@datetime(hh),3600),@prod(@datetime(nn),60),@datetime(ss))
exit @diff(%%end,%%begin) |
_________________ [ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial! |
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Mon Apr 04, 2005 8:40 pm Post subject: |
|
|
Interesting  _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
Hooligan VDS Developer


Joined: 28 Oct 2003 Posts: 480 Location: California
|
Posted: Mon Apr 04, 2005 10:02 pm Post subject: |
|
|
Very interesting... (Good job, Skit!)
Hooligan _________________ Hooligan
Why be normal? |
|
| Back to top |
|
 |
Hooligan VDS Developer


Joined: 28 Oct 2003 Posts: 480 Location: California
|
Posted: Mon Apr 04, 2005 10:11 pm Post subject: |
|
|
Whats even more interesting, is that you're doing one more @succ() operation in the one-liner. (Yet it's still faster?!?!?) Or did I count wrong?
Hooligan _________________ Hooligan
Why be normal? |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
|
| Back to top |
|
 |
jules Professional Member


Joined: 14 Sep 2001 Posts: 1043 Location: Cumbria, UK
|
Posted: Tue Apr 05, 2005 7:59 am Post subject: |
|
|
On the whole, I think it is better to write code that is easy to understand and debug, than sacrifice this for a 20% speed gain that will probably never be noticed. If there is an error somewhere in that bunch of nested functions, you'll have a hard job finding it. If speed is that much of an issue, you probably shouldn't be doing it using an interpreted script language in the first place. _________________ The Tech Pro
www.tech-pro.net |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Tue Apr 05, 2005 8:13 am Post subject: |
|
|
Julian, I created this code to see which option is faster, so it can be used in DSU files which need to be fast (like my database DSU). But I agree with you that if you create code of which speed is not the biggest problem, you should use the first method, which is far more easier to understand...  _________________ [ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial! |
|
| Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Tue Apr 05, 2005 9:59 am Post subject: |
|
|
good find skit
serge _________________
|
|
| Back to top |
|
 |
vdsalchemist Admin Team

Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Fri Jun 03, 2005 2:06 am Post subject: |
|
|
Skit,
You have stumbled upon a known issue with all programming languages. It requires less memory to be searched and parsed when used in a single line of code but the trade off is not worth it. Not even in a DSU. Spegetti code is never good. Let me know 6months from now if you can still read that DSU's code when your customers need it upgraded. When you try to put as much as you can on one line of code what will happen is errors will creep in and since it is so jumbled you will not be able to locate it. You will then have to figure out how to either separate the line into multiple lines or re-write the code.
IMHO no one should ever take this route when programming todays computers since they are so much faster than machines used 20 to 30 years ago or even 10 years ago. Actually there are many things I have seen in others VDS code that if it was not for the fact that everyone does it I would have never done it that way. For instance I would not use the goto command so much if it was not for the fact that just about no one here really understands the importance of structured programming. Under other languages it is tabo to use the goto unless it is absolutely nessary to bring the US Space Shuttle back down to earth safely and there just is no other option. Luckily most everyone that uses the goto command at least has a goto that returns to the label that originally called the first goto command. That is the only reason I have not really said anything about it before but when you program has more than 5000 lines you may need to start using Structured Programming technics.
Well I guess I can get off of my Soap Box for awhile but I did try to submit demo's with my DLL's that used structured programming but I kept getting so many questions about how they work that I had to drop the notion with my demos and go back to using goto's. _________________ Home of
Give VDS a new purpose!
 |
|
| Back to top |
|
 |
JRoza Contributor


Joined: 17 Aug 2003 Posts: 182 Location: Netherlands
|
Posted: Fri Jun 03, 2005 6:34 am Post subject: |
|
|
Hear, hear!
I fully agree with Dragonsphere.
My coding was never the shortest when compared to that of some collegue programmers, but mine could be interpreted by anyone in a short time whereas the coding of the "turbo-whizzkids" was very fast and compact but no one knew what the hell was going on after a year after the original programmer left the company.
And since my hair turned gray and even i had some trouble getting into old code in a short time I started using inline documentation in my code.
So now my code reads like a storybook and everyone should be able to get to grips with it in a flash.
"Gray dove" Jan |
|
| Back to top |
|
 |
jules Professional Member


Joined: 14 Sep 2001 Posts: 1043 Location: Cumbria, UK
|
Posted: Fri Jun 03, 2005 8:33 am Post subject: |
|
|
I entirely agree. One of my memories of when I started as a programmer, 30 years ago, was of trying to find a bug in a program written by someone who had left, in which there were no comments, and many of the variables were named after characters in Star Trek!
One of the reason VDS has never allowed more than one command on a line, is because of my memories of trying to figure out programs in other languages that were written like that.
VDS was really not designed for structured programming, and I think that is actually one of the benefits of it, because it enables you to knock together little applications very quickly, much quicker than you could do in another language where you are forced into using a structured approach. _________________ The Tech Pro
www.tech-pro.net |
|
| Back to top |
|
 |
vdsalchemist Admin Team

Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Fri Jun 03, 2005 2:37 pm Post subject: |
|
|
Jules,
I agree that VDS was originally meant to be a simple language to allow a programmer or non-programmer to knock together a simple utility. You have to agree though that the VDS today is not the VDS that you originally wrote. It has changed and grown. Now people are using it in business more and more. We are no longer just using it as a hobbiest language. We are writting real applications with it and building bigger and bigger programs with it. A program with a few 100 lines of code is no big deal but programs like some of those I have seen written here are too long to not apply structure to them.
A 20% increase in speed is not worth days of scratching ones head. I may combine 2 or 3 functions into a single line but only when processing events and only if I comment them. Anyway one of my issues I have with most of the code I see here is like the line of code below.
| Code: | | %x = @SENDMSG(@WINEXISTS(~MyElement),@SUM($1000,54),0,@SUM($20,$1)) |
Grant it this line is taken out of context but even in the program itself I have no idea what the numbers mean? Please anyone using numeric values in their code write a comment or assign the numeric value to a descriptive variable name. This way I don't have to ask what the code means, it will be self explanatory. I guess that last sentence is what structured programming is all about.
Write code that when someone reads it the code is self explanatory.
If you are just starting out programming I would suggest that you get a book on structured programming and make it a habbit. Don't short cut programming. It is already hard enough so don't make it harder. Conform to the KISS methodology (Keep, It, Simple, Silly). You will enjoy this thing they call programming much more.
This is not to pick on Skit directly I know he means well but I don't agree with his 20% theory. After reading and figuring out his code some what it seems that his code is merely load testing the @succ() function. His code is not an accurate depection of the speed of VDS with combind functions and without combind functions since he only used a single function in his test case. Also a lot of time was prob. wasted in the @datetime functions. If I ever get a chance I will see if I can load test several VDS applications with 'Mercury LoadRunner' and let you guys see the results. _________________ Home of
Give VDS a new purpose!
 |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Sat Jun 04, 2005 11:28 pm Post subject: |
|
|
Dragonsphere, I agree with you code needs to be commented, and like your @sendmsg example, numeric values should be stored in variables, but I don't do both a lot because I just don't know how to write down the comments... Most of the time, when I dó try to put comments on every line, I remove them a few minutes later, just because they are unnecessary (or well, that is what I think of them). That is why today I mostly only add comments at the beginning of functions, subs, labels and big blocks of code which do special things.
For school I had to work on a Visual Basic .NET project in which we created a huge customer database and everything related with it. Because only 2 of the 6 people of our project group knew enough about programming/databases/VB, we put comments everywhere. Unfortunately, because these other people don't understand the logic about programming, the comments were overwhelming. For every line in our program, we had to add two or more lines of comments for letting them understand what it does. Lines which combined VB functions and SQL queries even took 8 or 10 lines!
Maybe one could give some examples about how to comment a program well, so it is readable for other people? Not only for Visual Basic, but for all programming languages in common?  _________________ [ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial! |
|
| Back to top |
|
 |
vdsalchemist Admin Team

Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Sun Jun 05, 2005 5:48 am Post subject: |
|
|
| Skit3000 wrote: | For school I had to work on a Visual Basic .NET project in which we created a huge customer database and everything related with it. Because only 2 of the 6 people of our project group knew enough about programming/databases/VB, we put comments everywhere. Unfortunately, because these other people don't understand the logic about programming, the comments were overwhelming. For every line in our program, we had to add two or more lines of comments for letting them understand what it does. Lines which combined VB functions and SQL queries even took 8 or 10 lines!
Maybe one could give some examples about how to comment a program well, so it is readable for other people? Not only for Visual Basic, but for all programming languages in common?  |
Ummm who ever your professor in school is should not have made you do this. It should not be nessessaray to comment every single line of code.
You are right. Place comments at the begining of each programmer defined sub-routine, function, and in VDS user defined command unles the command or function is just a few simple lines. I really only comment when the program is doing something that is complex. I would venture to say that you should not have to teach others how to program through commenting your code, that is what they write 100's of 1,000's of books everyday about.
See you should not have to comment the following code. Anyone with the VDS help file would know what this code does.
| Code: |
:evloop
wait event,0.003
%E = @event()
If %E
goto %E
End
goto evloop
:TIMER
If @Equal(@Winpos(VDS UUCoder,S),2)
Dialog Hide
End
goto evloop |
On the other hand you should comment the following VDS functions. It really does not matter what language you are writting in they all need some kind of comments. Skit I am not saying that you don't comment your code. I am not trying to single you out or any other one person. I am just as bad as anyone here and I have gotten lazy about some of my coding practices. It's not just the comments but the flow of the code. How does one piece of code flow into another. In VDS use sub-routines/functions/commands and give them descriptive names it will help others understand what your code does. Eventhough the code below has no comments you can at least tell what their ententions are just by the name of the sub-routines.
| Code: |
:UUDecode_String
%z = 1
%u =
%x =
repeat
if @Not(@Greater(%z,@len(%2)))
%x = @SubStr(%2,%z,@Sum(%z,3))
if @not(@Equal(@len(%x),4))
repeat
%x = %x@chr(32)
until @Equal(@len(%x),4)
End
%u = %u@UUDecode(Set,%x,%3)
End
%z = @Sum(%z,4)
Until @Greater(%z,@len(%2))
%%return = %u
Exit %%return
:UUDecode_File
%%InFile = %2
%%OutPath = %3
If %%CallBack
CallBack UUDecode,Begin
End
%P = 45
directory change,@Path(%%InFile)
BINFILE OPEN,1,%%InFile,READ
%%totFileSize = @BINFILE(SIZE,1)
%%FilesFound = 0
%%cnt = 0
%H =
While @Not(@BINFILE(EOF,1))
BINFILE SEEK,1,%%cnt
%H = @Binfile(READ,1,TEXT,5)
If @Not(@Equal(%H,begin))
BINFILE SEEK,1,%%totFileSize
BINFILE CLOSE,1
Error 65000
%%Return =
Exit %%Return
End
BINFILE SEEK,1,@Diff(%%totFileSize,5)
%H = @Binfile(READ,1,TEXT,3)
If @Not(@Equal(%H,end))
BINFILE SEEK,1,%%totFileSize
BINFILE CLOSE,1
Error 65000
%%Return =
Exit %%Return
End
%H =
%U = @chr(32)
Repeat
BINFILE SEEK,1,%%cnt
%H = %H@chr($@Trim(@Binfile(READ,1,HEX,1)))
%U = @Asc(@SubStr(%H,@Len(%H)))
%%cnt = @Succ(%%cnt)
Until @Equal(%U,10)
If @Equal(@SubStr(%H,1,5),begin)
%%FilesFound = @Sum(%%FilesFound,1)
If %%OutPath
Directory create,%%OutPath
%N = %%OutPath@Trim(@SubStr(%H,11,@len(%H)))
Else
%N = @Path(%%InFile)@Trim(@SubStr(%H,11,@len(%H)))
End
If %%CallBack
CallBack UUDecode,Creating,%N
END
If @Equal(%%Status,PAUSE)
REPEAT
CallBack UUDecode,PAUSED
WAIT 1
Until @Equal(%%Status,PLAY)@Equal(%%Status,STOP)
ElsIf @Equal(%%Status,STOP)
BINFILE CLOSE,1
%%Return =
Exit %%Return
End
BINFILE OPEN,2,%N,CREATE
Repeat
%L =
%V =
BINFILE SEEK,1,%%cnt
%%Byte = @Asc(@chr($@Trim(@Binfile(read,1,HEX,1))))
%%Bytes = @Diff(%%Byte,32)
if %%Bytes
end
Repeat
BINFILE SEEK,1,%%cnt
%V = %V@chr($@Trim(@Binfile(READ,1,HEX,1)))
%U = @Asc(@SubStr(%V,@len(%V)))
%%cnt = @Succ(%%cnt)
Until @Equal(%U,10)
if %V
if @Not(@Equal(@SubStr(%V,1,3),end))
if @Not(@Equal(@SubStr(%V,1),@chr(96)))
%L = @SubStr(%V,2,@len(%V))
%Z = @UUDecode(String,@SubStr(%L,1,@Diff(@Len(%L),2)),ASCII)
If %%CallBack
%%PerBytes = @format(@fmul(@fdiv(%%cnt,%%totFileSize),100),3.0)
%%PerBytesLeft = @format(@fSub(100,%%PerBytes),3.0)
CallBack UUDecode,Progress,%N,%%totFileSize,%%cnt,%%PerBytes,%%PerBytesLeft
End
If @Equal(%%Status,PAUSE)
REPEAT
CallBack UUDecode,PAUSED
WAIT 1
Until @Equal(%%Status,PLAY)@Equal(%%Status,STOP)
ElsIf @Equal(%%Status,STOP)
BINFILE CLOSE,1
BINFILE CLOSE,2
If @File(%N)
FILE DELETE,%N
End
%%Return =
Exit %%Return
End
BINFILE WRITE,2,BINARY,%Z
End
End
End
Until @Equal(@SubStr(%V,1,3),end)
If %%CallBack
%%PerBytes = @format(@fmul(@fdiv(%%cnt,%%totFileSize),100),3.0)
%%PerBytesLeft = @format(@fSub(100,%%PerBytes),3.0)
CallBack UUDecode,Progress,%N,%%totFileSize,%%cnt,%%PerBytes,%%PerBytesLeft
End
If @Equal(%%Status,PAUSE)
REPEAT
CallBack UUDecode,PAUSED
WAIT 1
Until @Equal(%%Status,PLAY)@Equal(%%Status,STOP)
ElsIf @Equal(%%Status,STOP)
BINFILE CLOSE,1
BINFILE CLOSE,2
If @File(%N)
FILE DELETE,%N
End
%%Return =
Exit %%Return
End
Else
BINFILE SEEK,1,%%totFileSize
BINFILE CLOSE,1
Error 65000
%%Return =
Exit %%Return
End
WEND
BINFILE CLOSE,1
BINFILE SEEK,2,0
%Q = @Trim(@BinFile(READ,2,TEXT,5))
BINFILE CLOSE,2
IF @Equal(%Q,GUARD)
If %%CallBack
CallBack UUDecode,Compress,Begin
END
%M = @Path(%N)@Name(%N).@SubStr(@Ext(%N),1,@Pred(@Len(@Ext(%N))))_
rem Info %N@CR()%M
File rename,%N,%M
rem Info %N@CR()%M
%N = @Guardian(UnCompress,%M,@Path(%M))
File Delete,%M
If %%CallBack
CallBack UUDecode,Compress,"End"
END
Else
BINFILE CLOSE,2
End
If %%CallBack
CallBack UUDecode,"End",%N
END
%%Return = %N
Exit %%Return
|
_________________ Home of
Give VDS a new purpose!
 |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Sun Jun 05, 2005 8:54 am Post subject: |
|
|
| DragonSphere wrote: | | Skit I am not saying that you don't comment your code. I am not trying to single you out or any other one person. I am just as bad as anyone here and I have gotten lazy about some of my coding practices. |
I don't mind if you would single me out, since you keep giving tips about how to do things better. I usually also skip the parts of code from commenting, if I know what it does, but I can understand it might not seem so easy for others. _________________ [ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial! |
|
| Back to top |
|
 |
|
|
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 You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|