Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - One script block or not?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

One script block or not?

 Post Reply Post Reply
Author
ngaisteve1 View Drop Down
Groupie
Groupie
Avatar

Joined: 26 December 2002
Location: Malaysia
Status: Offline
Points: 169
Post Options Post Options   Thanks (0) Thanks(0)   Quote ngaisteve1 Quote  Post ReplyReply Direct Link To This Post Topic: One script block or not?
    Posted: 25 July 2003 at 12:45am
Just want to ask about writing code. I know that each time there is a <%%>, there will be a server trip. In order to minimize server trip, we should have one asp script block, which is the whole page just one <%%>. However, by doing this, can make the whole page every difficult to read, the indention etc. If not using this way, then will affect the performance cause by many server trip. So, what should be the best practice? I check out some big system, for webwiz is not using one script block and snitz is using one script block.
Back to Top
stephen View Drop Down
Newbie
Newbie


Joined: 23 August 2002
Location: United Kingdom
Status: Offline
Points: 33
Post Options Post Options   Thanks (0) Thanks(0)   Quote stephen Quote  Post ReplyReply Direct Link To This Post Posted: 25 July 2003 at 2:27am

From what other well experienced developers have said, including on this forum, it makes very little difference. This is an interesting post for me as I would be testing performance with these two methods as part of my final project.

Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 25 July 2003 at 8:17am
On a powerful web server you will not see much performance difference, but from a development outloook indenting code makes it infinitely easier to read.

I had a friend a couple years back that went to the trouble of creating a program that would remove all empty space from his code and FTP that code to his web server. There was about a 5-10% decrease in file, but very little difference in execution speed.

My preference is to use blocks of ASP and do as much code in one space as possible and then reference variables and arrays as needed. This means that all my SQL statements are executed and processed at one time and stored in arrays for use later. My typical page has a dense section of ASP at the top and bottom and small bit dispersed through the center with HTML elements.

Another note:
There is no additional server trip made for the execution of any single ASP page. Only one trip is made to the server which then processes and parses the request. What you are talking about is additional processing/ execution time which is why a 200 line page with no ASP loads faster than a page with 200 lines of ASP.

Back to Top
dpyers View Drop Down
Senior Member
Senior Member


Joined: 12 May 2003
Status: Offline
Points: 3937
Post Options Post Options   Thanks (0) Thanks(0)   Quote dpyers Quote  Post ReplyReply Direct Link To This Post Posted: 26 July 2003 at 11:54am

"How do I make my ASP pages more efficient" - http://www.aspfaq.com/show.asp?id=2424

"Does order matter when using different languages in ASP" - http://www.aspfaq.com/show.asp?id=2045

 

The way it was explained to me many moons ago was that when you call a page with the .asp extension, an instance of asp.dll is invoked with associated server overhead to establish the instance. When the %> is found, the instance is shutdown - again with associated overhead. Intertwining asp and html either instantiates asp.dll for the page, or shuts it down whenever you change between asp and html. This little snippet from MS appears to support that ...

"Keep blocks of ASP server-side script together, rather than switching back and forth between server-side and client-side code. This switching usually happens when concatenating HTML with simple values from ASP, as when you are writing out an HTML table:

<%    For iCtr = 1 to 10  %>
<TR><TD>Counting ... <%= iCtr %></TD></TR>
<%    Next  %>


You can improve the code's by making it a single script block:


<%    For iCtr = 1 to 10
Response.Write "<tr><td>Counting " & iCtr & "</td></tr>"
      Next
%>


This technique has shown measurable and significant performance improvements."

BTW... The problem is even more pronounced with javascript... the interpreter instantiates after each CF/LF. If you note the javascripts available on the code sites. Those complicated ones done by very experienced javascript developers have had the cr/lf's removed. The scripts are all on a single line.

Wnen all is said and done however, being able to work with our code is also very important. I'd only worry about it if you have performance problems with the page, or if you have high utilization.

 



Edited by dpyers

Lead me not into temptation... I know the short cut, follow me.
Back to Top
WebWiz-Bruce View Drop Down
Admin Group
Admin Group
Avatar
Web Wiz Developer

Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9844
Post Options Post Options   Thanks (0) Thanks(0)   Quote WebWiz-Bruce Quote  Post ReplyReply Direct Link To This Post Posted: 26 July 2003 at 12:17pm

I did a test once, I had a page that was around 1000 lines long with 100's ASP blocks all over the place in the HTML.

I converted the whole thing to use only one ASP block and ran both the original and new versions seeing how long they took to process all the way down to 0.0000000 of a micro second. When I ran the tests there was no difference in process time at all.

Of course this maybe slightly different if the server was under heavy load.

Back to Top
the boss View Drop Down
Senior Member
Senior Member
Avatar

Joined: 19 January 2003
Location: Saudi Arabia
Status: Offline
Points: 1727
Post Options Post Options   Thanks (0) Thanks(0)   Quote the boss Quote  Post ReplyReply Direct Link To This Post Posted: 26 July 2003 at 2:34pm
ASp came out when the most powerful server ws a dual processor pentium II 500 MHz..in todays age when we have much more powerful computers and processors like AMD and Intel Xeon...u will not see any visible performance  degradation unless u write such a worst code which uses up all the processor power...

Back to Top
Bunce View Drop Down
Senior Member
Senior Member
Avatar

Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bunce Quote  Post ReplyReply Direct Link To This Post Posted: 26 July 2003 at 7:36pm

The differences were more prominent in ASP2.0 

I believe that MS article was written at that time.

Cheers,
Andrew

There have been many, many posts made throughout the world...
This was one of them.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.