473,473 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Variables vs. On-The-Fly Programming

I have included two pseudo-code examples below. The first shows me
allocating memory via a variable and using it repeatedly. The second
shows me taking the "direct route" to the data.

For a web application performing multiple operations in a short amount
of time, which procedure would maximize speed on the server? (Is it
better to use a variable? Is it best to use the "direct route"? Or is
it a moot point because they both use the same resources to get where
they need to go anyway?)

Please note that I am looking for answers *ONLY* pertaining to server
speed and resources. I understand that variables are "easier" for a
programmer to use, but I want to know what makes the server run
smoother.

Thanks in advance!
EXAMPLE 1:

(coll1 is a collection of directory strings...)

Dim temp as String = New IO.DirectoryInfo(coll1.Item(i)).name

if InStr(temp, "xyz") then...
if temp = "xyz123" then...
if Right(temp, 3) = "123" then...
EXAMPLE 2:

(coll1 is a collection of directory strings...)

if InStr(New IO.DirectoryInfo(coll1.Item(i)).name, "xyz") then...
if New IO.DirectoryInfo(coll1.Item(i)).name = "xyz123" then...
if Right(New IO.DirectoryInfo(coll1.Item(i)).name, 3) = "123" then...

Nov 21 '05 #1
2 1175
> For a web application performing multiple operations in a short amount
of time, which procedure would maximize speed on the server? (Is it
better to use a variable? Is it best to use the "direct route"? Or is
it a moot point because they both use the same resources to get where
they need to go anyway?) Moot point! See 80/20 rule below.

If I really needed the explaining variable (your temp) I would include it,
if I didn't need it I would not. Need of the explaining variable is based on
readability of the code, not whether it performed better or not. The
compiler or the JIT during optimization may use a temp variable if you don't
include it, or it may ignore the temp variable if you do, hence I would not
be concerned with it unless its been identified & proven (see 80/20 rule
below)

http://www.refactoring.com/catalog/i...gVariable.html
http://www.refactoring.com/catalog/inlineTemp.html
http://www.refactoring.com/catalog/r...WithQuery.html
Consider the 80/20 rule! That is 80% of the execution time of your program
is spent in 20% of your code. I will optimize (worry about performance) the
20% once that 20% has been identified & proven to be a performance problem
via profiling (CLR Profiler is one profiling tool).

For info on the 80/20 rule & optimizing only the 20% see Martin Fowler's
article "Yet Another Optimization Article" at
http://martinfowler.com/ieeeSoftware...timization.pdf

Please note that I am looking for answers *ONLY* pertaining to server
speed and resources. I understand that variables are "easier" for a
programmer to use, but I want to know what makes the server run
smoother.

Info on the CLR Profiler:
http://msdn.microsoft.com/library/de...nethowto13.asp

http://msdn.microsoft.com/library/de...anagedapps.asp

In addition to the above articles, The following articles provide
information on writing .NET code that performs well. I believe one of the
covers how to use Performance Monitor under Control Panel to monitor the
memory usage of your app.

http://msdn.microsoft.com/architectu...l/scalenet.asp

http://msdn.microsoft.com/library/de...anagedcode.asp

http://msdn.microsoft.com/library/de...anagedapps.asp

http://msdn.microsoft.com/library/de...vbnstrcatn.asp

http://msdn.microsoft.com/library/de...tchperfopt.asp

http://msdn.microsoft.com/library/de...tperftechs.asp
Hope this helps
Jay
<im********@aol.com> wrote in message
news:ch********@odah37.prod.google.com...I have included two pseudo-code examples below. The first shows me
allocating memory via a variable and using it repeatedly. The second
shows me taking the "direct route" to the data.

For a web application performing multiple operations in a short amount
of time, which procedure would maximize speed on the server? (Is it
better to use a variable? Is it best to use the "direct route"? Or is
it a moot point because they both use the same resources to get where
they need to go anyway?)

Please note that I am looking for answers *ONLY* pertaining to server
speed and resources. I understand that variables are "easier" for a
programmer to use, but I want to know what makes the server run
smoother.

Thanks in advance!
EXAMPLE 1:

(coll1 is a collection of directory strings...)

Dim temp as String = New IO.DirectoryInfo(coll1.Item(i)).name

if InStr(temp, "xyz") then...
if temp = "xyz123" then...
if Right(temp, 3) = "123" then...
EXAMPLE 2:

(coll1 is a collection of directory strings...)

if InStr(New IO.DirectoryInfo(coll1.Item(i)).name, "xyz") then...
if New IO.DirectoryInfo(coll1.Item(i)).name = "xyz123" then...
if Right(New IO.DirectoryInfo(coll1.Item(i)).name, 3) = "123" then...

Nov 21 '05 #2
I should add, that ACT (Application Center Test) is a utility included with
VS.NET allows you to stress test & performance test you web applications.

"Performance Testing - Microsoft .NET Web Applications" from MS Press by
Microsoft Application Consulting and Engineering (ACE) Team provides a
wealth of information on performance & stress testing your applications.

Hope this helps
Jay

<im********@aol.com> wrote in message
news:ch********@odah37.prod.google.com...
I have included two pseudo-code examples below. The first shows me
allocating memory via a variable and using it repeatedly. The second
shows me taking the "direct route" to the data.

For a web application performing multiple operations in a short amount
of time, which procedure would maximize speed on the server? (Is it
better to use a variable? Is it best to use the "direct route"? Or is
it a moot point because they both use the same resources to get where
they need to go anyway?)

Please note that I am looking for answers *ONLY* pertaining to server
speed and resources. I understand that variables are "easier" for a
programmer to use, but I want to know what makes the server run
smoother.

Thanks in advance!
EXAMPLE 1:

(coll1 is a collection of directory strings...)

Dim temp as String = New IO.DirectoryInfo(coll1.Item(i)).name

if InStr(temp, "xyz") then...
if temp = "xyz123" then...
if Right(temp, 3) = "123" then...
EXAMPLE 2:

(coll1 is a collection of directory strings...)

if InStr(New IO.DirectoryInfo(coll1.Item(i)).name, "xyz") then...
if New IO.DirectoryInfo(coll1.Item(i)).name = "xyz123" then...
if Right(New IO.DirectoryInfo(coll1.Item(i)).name, 3) = "123" then...

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: jyu.james | last post by:
I'm trying to detect reads of uninitialized global variables (that are declared in one file, and used in another as an extern). I know that ANSI C initializes all global variables to 0, however,...
5
by: Frank Wisniewski | last post by:
I use static variables in my asp.net apps instead of application variables to store global parameters, its worked well for me so far but I was wondering if it is efficient. Does anyone know how...
4
by: Nick Dreyer | last post by:
Is it possible to see public class variables of a COM addin in Excel 97 VBA? I have successfully created the (Visual Basic 2003 .NET) COM and referenced it in an Excel 97 VBA project. The VBA...
1
by: nicepg | last post by:
Hi, i m new in C#, and i m trying to prgramm a calculator program in web application. My program work very well using a static variables but i need to change these variables to session...
1
by: BillE | last post by:
My application relies on session variables to keep track of the currently selected customer. When a new window is opened using File-New-Window in Internet Explorer, the session variables are...
0
by: sarma | last post by:
Hi, I am using MySQL 5 as my database I am not able to set variables query_alloc_block_size, query_prealloc_size and read_buffer_size. I tried SET GLOBAL command. I tried in Windows env...
3
by: HardHackz | last post by:
Are there any variables like %HOMEDIR%, %USERNAME%, etc. that batch has for C++?
2
by: =?windows-1252?Q?=22=C1lvaro_G=2E_Vicario=22?= | last post by:
Is there any way to tell PHP predefined variables ($GLOBALS, $argv, $argc, $_GET, $_POST…) from *global* user-defined variables? Neither $GLOBALS nor get_defined_vars() put user data apart. I’m...
18
by: Bruce | last post by:
When I do this: <input id="someName" type="text"> <script type="text/javascript"> alert(someName.nodeName); </script> Both IE6 and Firefox alert("INPUT"). Why isn't "someName" undefined?
1
by: kkshansid | last post by:
i want to pass both variables($q1 and value of select) from this php page to java script so that i can get both variables in second php file srt.php <script type="text/javascript"...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.