By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,740 Members | 844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,740 IT Pros & Developers. It's quick & easy.

ASPX Performance - Slow?

P: n/a
I am writing some kind of network testing tool and I have wrote the
following code in ASP.NET with C#

int size= 10048576; // around 10 MB data
string buffer = "";
for (int j=1; j<=1024; j++) {
buffer = String.Concat(buffer, "x");
// I tried buffer += "x"; same performance
}

for (int i=1; i<=(size/1024); i++) {
Response.Write(buffer);
// I tried using <asp:literal> same thing
}

From another computer, I downloaded this file by making that as a link in
HTML. It was so slow.. I get around 8 Mbps on a 100 Mbps LAN.. In order
to compare, I tested with a real JPG file I got 25 Mbps! Also, I wrote the
same thing in PHP using exactly same algorithm. I got around 25 Mbps!

Anyone knows why ASPX performance is slow? is it configruation problem?
IIS? or is it Response.write not good? I also tried using <asp: literal>
same thing.. help..

Thanks in advance

Nov 18 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Try your test and replace String.Concat with a StringBuilder. Basically in
your current code you are doing string allocations on each pass of the loop.
So what you want is something like:

int size= 10048576; // around 10 MB data
System.Text.StringBuilder sb=new System.Text.StringBuilder()
string buffer = "";
for (int j=1; j<=1024; j++) {
sb.Append("x");
// I tried buffer += "x"; same performance
}
buffer=sb.ToString();

hth
Chris Torgerson

"BlueBall" <ba*************@hotmail.com> wrote in message
news:o2*******************@twister01.bloor.is.net. cable.rogers.com...
I am writing some kind of network testing tool and I have wrote the
following code in ASP.NET with C#

int size= 10048576; // around 10 MB data
string buffer = "";
for (int j=1; j<=1024; j++) {
buffer = String.Concat(buffer, "x");
// I tried buffer += "x"; same performance
}

for (int i=1; i<=(size/1024); i++) {
Response.Write(buffer);
// I tried using <asp:literal> same thing
}

From another computer, I downloaded this file by making that as a link in
HTML. It was so slow.. I get around 8 Mbps on a 100 Mbps LAN.. In order
to compare, I tested with a real JPG file I got 25 Mbps! Also, I wrote the
same thing in PHP using exactly same algorithm. I got around 25 Mbps!

Anyone knows why ASPX performance is slow? is it configruation problem?
IIS? or is it Response.write not good? I also tried using <asp: literal>
same thing.. help..

Thanks in advance


Nov 18 '05 #2

P: n/a
String concatenation, whether you user String.Concat or +=, is
incredibly expensive because it makes a new copy of the string every
time. Try this instead:

int size= 10048576; // around 10 MB data
StringBuilder buffer = new StringBuilder(size);
for (int j=1; j<=size; j++)
{
buffer.Append("x");
}
Response.Write(buffer.ToString());

-Jason
BlueBall wrote:
I am writing some kind of network testing tool and I have wrote the
following code in ASP.NET with C#

int size= 10048576; // around 10 MB data
string buffer = "";
for (int j=1; j<=1024; j++) {
buffer = String.Concat(buffer, "x");
// I tried buffer += "x"; same performance
}

for (int i=1; i<=(size/1024); i++) {
Response.Write(buffer);
// I tried using <asp:literal> same thing
}

From another computer, I downloaded this file by making that as a link in
HTML. It was so slow.. I get around 8 Mbps on a 100 Mbps LAN.. In order
to compare, I tested with a real JPG file I got 25 Mbps! Also, I wrote the
same thing in PHP using exactly same algorithm. I got around 25 Mbps!

Anyone knows why ASPX performance is slow? is it configruation problem?
IIS? or is it Response.write not good? I also tried using <asp: literal>
same thing.. help..

Thanks in advance


Nov 18 '05 #3

P: n/a
StringBuilder doesn't help because in my code, I don't actually repeat the
buffer generating part.

Try to run it on your IIS, you will see what I mean. In order to verify
this is an ASPX performance problem (or possible my coding algorithm or
config problem), I have created an old fashion ASP page:

<%
dim i, j, size, buffer
size= 10048576
for i = 1 to 1024
buffer = buffer & "x"
next
for j = 1 to (size / 1024)
response.write(buffer)
next
%>

Create a hyper link in a new HTML page and link to this ASP page, and then
create another link that links to ASPX page you wrote (or the one I posted
earlier). You can see the BIG difference in performance. ASP page is
faster than ASPX page at least 3 times... I am frustrated!!!

B.B.

"Jason DeFontes" <ja***@defontes.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
String concatenation, whether you user String.Concat or +=, is
incredibly expensive because it makes a new copy of the string every
time. Try this instead:

int size= 10048576; // around 10 MB data
StringBuilder buffer = new StringBuilder(size);
for (int j=1; j<=size; j++)
{
buffer.Append("x");
}
Response.Write(buffer.ToString());

-Jason
BlueBall wrote:
I am writing some kind of network testing tool and I have wrote the
following code in ASP.NET with C#

int size= 10048576; // around 10 MB data
string buffer = "";
for (int j=1; j<=1024; j++) {
buffer = String.Concat(buffer, "x");
// I tried buffer += "x"; same performance
}

for (int i=1; i<=(size/1024); i++) {
Response.Write(buffer);
// I tried using <asp:literal> same thing
}

From another computer, I downloaded this file by making that as a link in HTML. It was so slow.. I get around 8 Mbps on a 100 Mbps LAN.. In order to compare, I tested with a real JPG file I got 25 Mbps! Also, I wrote the same thing in PHP using exactly same algorithm. I got around 25 Mbps!

Anyone knows why ASPX performance is slow? is it configruation problem?
IIS? or is it Response.write not good? I also tried using <asp: literal> same thing.. help..

Thanks in advance


Nov 18 '05 #4

P: n/a
BlueBall wrote:
StringBuilder doesn't help because in my code, I don't actually repeat the
buffer generating part.

Try to run it on your IIS, you will see what I mean. In order to verify
this is an ASPX performance problem (or possible my coding algorithm or
config problem), I have created an old fashion ASP page:

<%
dim i, j, size, buffer
size= 10048576
for i = 1 to 1024
buffer = buffer & "x"
next
for j = 1 to (size / 1024)
response.write(buffer)
next
%>

Create a hyper link in a new HTML page and link to this ASP page, and then
create another link that links to ASPX page you wrote (or the one I posted
earlier). You can see the BIG difference in performance. ASP page is
faster than ASPX page at least 3 times... I am frustrated!!!

B.B.


I think I can see where your problem is.

By default, ASP does not buffer output whereas ASP.NET does. Therefore,
your ASP code is sending the response directly to the client, whereas
ASP.Net is building the entire output before sending.

Try setting Response.BufferOuput to false in your Page.Load event
handler and then try your test again.


--

Ed Courtenay
[MCP, MCSD]
http://www.edcourtenay.co.uk
Nov 18 '05 #5

P: n/a
I tried adding it but that makes the performance even worse...it's like
crawling. I am posting my 2 pieces of codes, so that anyone can try it on
your server. Thanks in advance!

Create a HTML page and make 2 hyper links pointing to these 2 files, then
Right-click -> save target as -> You will see the BIG difference between the
performance between the two.

-------------------------------------------------------
test.aspx
-------------------------------------------------------

<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<script language="C#" runat="server">
void Page_Load() {

// Response.BufferOutput = false;
int size= 10485760; // around 10 MB data
StringBuilder buffer = new StringBuilder(size);
String str = "";

for (int i=1; i<=1024; i++)
buffer.Append("x");

str = buffer.ToString();

for (int j=1; j<=size/1024; j++)
Response.Write(str);
} // load
</script>

-------------------------------------------------------
test.asp
-------------------------------------------------------

<%
dim i, j, size, buffer
size = 10485760

for i = 1 to 1024
buffer = buffer & "x"
next

for j = 1 to (size / 1024)
response.write(buffer)
next

%>

-------------------------------------------------------

"Ed Courtenay" <re*****************************@edcourtenay.co.uk > wrote in
message news:%2****************@tk2msftngp13.phx.gbl...
BlueBall wrote:
StringBuilder doesn't help because in my code, I don't actually repeat the buffer generating part.

Try to run it on your IIS, you will see what I mean. In order to verify
this is an ASPX performance problem (or possible my coding algorithm or
config problem), I have created an old fashion ASP page:

<%
dim i, j, size, buffer
size= 10048576
for i = 1 to 1024
buffer = buffer & "x"
next
for j = 1 to (size / 1024)
response.write(buffer)
next
%>

Create a hyper link in a new HTML page and link to this ASP page, and then create another link that links to ASPX page you wrote (or the one I posted earlier). You can see the BIG difference in performance. ASP page is
faster than ASPX page at least 3 times... I am frustrated!!!

B.B.


I think I can see where your problem is.

By default, ASP does not buffer output whereas ASP.NET does. Therefore,
your ASP code is sending the response directly to the client, whereas
ASP.Net is building the entire output before sending.

Try setting Response.BufferOuput to false in your Page.Load event
handler and then try your test again.


--

Ed Courtenay
[MCP, MCSD]
http://www.edcourtenay.co.uk

Nov 18 '05 #6

P: n/a
Well, I tried it, and your ASP was about 3x *slower* than your ASPX, and
my ASPX with the StringBuilder and only 1 call to Response.Write,
instead of your ~10000 calls, was about 1/3 faster than your ASPX. So
who knows... I imagine there are many, many factors that could affect
this, and our two samples hardly make a conclusive data set.

-Jason

BlueBall wrote:
StringBuilder doesn't help because in my code, I don't actually repeat the
buffer generating part.

Try to run it on your IIS, you will see what I mean. In order to verify
this is an ASPX performance problem (or possible my coding algorithm or
config problem), I have created an old fashion ASP page:

<%
dim i, j, size, buffer
size= 10048576
for i = 1 to 1024
buffer = buffer & "x"
next
for j = 1 to (size / 1024)
response.write(buffer)
next
%>

Create a hyper link in a new HTML page and link to this ASP page, and then
create another link that links to ASPX page you wrote (or the one I posted
earlier). You can see the BIG difference in performance. ASP page is
faster than ASPX page at least 3 times... I am frustrated!!!

B.B.

"Jason DeFontes" <ja***@defontes.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
String concatenation, whether you user String.Concat or +=, is
incredibly expensive because it makes a new copy of the string every
time. Try this instead:

int size= 10048576; // around 10 MB data
StringBuilder buffer = new StringBuilder(size);
for (int j=1; j<=size; j++)
{
buffer.Append("x");
}
Response.Write(buffer.ToString());

-Jason
BlueBall wrote:

I am writing some kind of network testing tool and I have wrote the
following code in ASP.NET with C#

int size= 10048576; // around 10 MB data
string buffer = "";
for (int j=1; j<=1024; j++) {
buffer = String.Concat(buffer, "x");
// I tried buffer += "x"; same performance
}

for (int i=1; i<=(size/1024); i++) {
Response.Write(buffer);
// I tried using <asp:literal> same thing
}

From another computer, I downloaded this file by making that as a link
in
HTML. It was so slow.. I get around 8 Mbps on a 100 Mbps LAN.. In
order
to compare, I tested with a real JPG file I got 25 Mbps! Also, I wrote
the
same thing in PHP using exactly same algorithm. I got around 25 Mbps!

Anyone knows why ASPX performance is slow? is it configruation problem?
IIS? or is it Response.write not good? I also tried using <asp:
literal>
same thing.. help..

Thanks in advance



Nov 18 '05 #7

P: n/a

"BlueBall" <ba*************@hotmail.com> wrote in message news:o2*******************@twister01.bloor.is.net. cable.rogers.com...
I am writing some kind of network testing tool and I have wrote the
following code in ASP.NET with C#

int size= 10048576; // around 10 MB data
string buffer = "";
for (int j=1; j<=1024; j++) {
buffer = String.Concat(buffer, "x");
// I tried buffer += "x"; same performance
}

for (int i=1; i<=(size/1024); i++) {
Response.Write(buffer);
// I tried using <asp:literal> same thing
}

From another computer, I downloaded this file by making that as a link in
HTML. It was so slow.. I get around 8 Mbps on a 100 Mbps LAN.. In order
to compare, I tested with a real JPG file I got 25 Mbps! Also, I wrote the
same thing in PHP using exactly same algorithm. I got around 25 Mbps!

Anyone knows why ASPX performance is slow? is it configruation problem?
IIS? or is it Response.write not good? I also tried using <asp: literal>
same thing.. help..

Thanks in advance



In addition to the other replies:

When did you time the performance? The first time an aspx page
is accessed, it gets compiled to native code. This will have a performance
hit, but only the first time this page is accessed (in the lifetime
of the application).
Neither php or asp have this automatic compile feature so there
you get no speed dirrerence between the first and second time.
Hans Kesting
Nov 18 '05 #8

P: n/a
1. You should try to use StringBuilder for concatenation. This will greatly
improve performance.

2. You are outputting buffer 9813 times. The problem is that ASP.NET saves
the output into temporary buffer and only when you done it outputs the
buffer to browser. The size of the buffer is preset to something big but
much less than 10Mb. And ASP.NET has to constantly expand the buffer as
needed when you are outputting it. Which is a big performance hit.
If you just bluntly set Response.Buffer = false then you going to have
another problem since ASP.NET will have to use IIS APIs every time you do
Response.Write which is another performance hit.
You can minimize it by seting Response.Buffer = true but calling
Response.Flush every 20th time.

George.
"BlueBall" <ba*************@hotmail.com> wrote in message
news:o2*******************@twister01.bloor.is.net. cable.rogers.com...
I am writing some kind of network testing tool and I have wrote the
following code in ASP.NET with C#

int size= 10048576; // around 10 MB data
string buffer = "";
for (int j=1; j<=1024; j++) {
buffer = String.Concat(buffer, "x");
// I tried buffer += "x"; same performance
}

for (int i=1; i<=(size/1024); i++) {
Response.Write(buffer);
// I tried using <asp:literal> same thing
}

From another computer, I downloaded this file by making that as a link in
HTML. It was so slow.. I get around 8 Mbps on a 100 Mbps LAN.. In order
to compare, I tested with a real JPG file I got 25 Mbps! Also, I wrote the
same thing in PHP using exactly same algorithm. I got around 25 Mbps!

Anyone knows why ASPX performance is slow? is it configruation problem?
IIS? or is it Response.write not good? I also tried using <asp: literal>
same thing.. help..

Thanks in advance


Nov 18 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.