Comparazione of the performance in I use of stringhe (English)
For the original Italian page, please click on the link: http://www.guru4.net/articoli/string-performance/default.aspx
They will come considered 7 various relative implementazioni to the cyclical concatenation of stringhe, verifying for every case the times of elaboration demands and increasing the number for concatenations from 200 until 100.000; in every cycle it will have to be put in line tightens it "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".
To - pure concatenation of stringhe in JScript
Implemented like of continuation:
<%@Language="JScript"%>
<html>
<body>
<%
var loops = 200;
var txt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
var t = new Date().getTime();
var s = "";
for(var i = 1; i < loops; i )
s = txt;
Response.Write(s);
Response.Write("<hr>Tempo esecuzione " loops " cicli: " ((new Date().getTime()) - t) " ms");
%>
</body>
</html>
B - I use repeated of Response.Write in JScript
Implemented like of continuation:
<%@Language="JScript"%>
<html>
<body>
<%
var loops = 200;
var txt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
var t = new Date().getTime();
for(var i = 1; i < loops; i )
Response.Write(txt);
Response.Write("<hr>Tempo esecuzione " loops " cicli: " ((new Date().getTime()) - t) " ms");
%>
</body>
</html>
C - I use of Array in JScript
Implemented like of continuation:
<%@Language="JScript"%>
<html>
<body>
<%
var loops = 200;
var txt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
var t = new Date().getTime();
var a = new Array();
for(var i = 1; i < loops; i )
a[a.length] = txt;
Response.Write(a.join(""));
Response.Write("<hr>Tempo esecuzione " loops " cicli: " ((new Date().getTime()) - t) " ms");
%>
</body>
</html>
D - pure concatenation of stringhe in VBScript
Implemented like of continuation:
<%@Language="VBScript"%>
<%
Option Explicit
%>
<html>
<body>
<%
Dim loops
Dim txt
Dim t
Dim i
loops = 200
txt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "
t = Timer()
Dim s
s = ""
For i = 1 To loops
s = s & txt
Next
Response.Write(s)
Response.Write("<hr>Tempo esecuzione " & loops & " cicli: " & Round((Timer() - t)*1000, 0) & " ms")
%>
</body>
</html>
And - I use repeated of Response.Write in VBScript
Implemented like of continuation:
<%@Language="VBScript"%>
<%
Option Explicit
%>
<html>
<body>
<%
Dim loops
Dim txt
Dim t
Dim i
loops = 200
txt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "
t = Timer()
For i = 1 To loops
Response.Write(txt)
Next
Response.Write("<hr>Tempo esecuzione " & loops & " cicli: " & Round((Timer() - t)*1000, 0) & " ms")
%>
</body>
</html>
F - I use of Array in VBScript
Implemented like of continuation:
<%@Language="VBScript"%>
<%
Option Explicit
%>
<html>
<body>
<%
Dim loops
Dim txt
Dim t
Dim i
loops = 200
txt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "
t = Timer()
Dim a
a = Array()
For i = 1 To loops
ReDim Preserve a(Ubound(a) 1)
a(UBound(a)) = txt
Next
Response.Write(Join(a, ""))
Response.Write("<hr>Tempo esecuzione " & loops & " cicli: " & Round((Timer() - t)*1000, 0) & " ms")
%>
</body>
</html>
G - I use of Array (previously determine the proportions) in VBScript
Implemented like of continuation:
<%@Language="VBScript"%>
<%
Option Explicit
%>
<html>
<body>
<%
Dim loops
Dim txt
Dim t
Dim i
loops = 200
txt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "
t = Timer()
Dim a
a = Array(loops)
ReDim a(loops)
For i = 0 To loops
a(i) = txt
Next
Response.Write(Join(a, ""))
Response.Write("<hr>Tempo esecuzione " & loops & " cicli: " & Round((Timer() - t)*1000, 0) & " ms")
%>
</body>
</html>
It turns out to you
The following table extension the detail of the times of execution (expressed in milliseconds) finds to you:
| loop | To | B | C | D | And | F | G |
| 200 * | 10 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|
| 500 | 30 | 10 | 0 | 31 | 0 | 0 | 0 |
| 1000 | 100 | 10 | 0 | 78 | 0 | 8 | 0 |
| 1500 | 271 | 20 | 10 | 200 | 0 | 20 | 12 |
| 2000 | 701 | 20 | 20 | 629 | 8 | 23 | 12 |
| 2500 | 1332 | 30 | 20 | 1145 | 8 | 39 | 12 |
| 3000 | 2083 | 40 | 30 | 1961 | 8 | 50 | 19 |
| 3500 | 3204 | 40 | 40 | 3145 | 12 | 50 | 19 |
| 4000 | 4716 | 40 | 40 | 4855 | 12 | 78 | 19 |
| 4500 | 6309 | 50 | 60 | 6398 | 12 | 98 | 31 |
| 5000 | 8633 | 50 | 60 | 8785 | 20 | 109 | 31 |
| 5500 | 10666 | 60 | 70 | 11145 | 20 | 121 | 39 |
| 6000 | 13039 | 70 | 80 | 13680 | 20 | 128 | 42 |
| 6500 | 16073 | 70 | 80 | 17043 | 20 | 148 | 43 |
| 7000 | 18958 | 80 | 90 | 20086 | 20 | 152 | 43 |
| 7500 | 22502 | 80 | 90 | 23605 | 20 | 160 | 43 |
| 8000 | 26228 | 90 | 100 | 27551 | 20 | 238 | 46 |
| 8500 | 29993 | 100 | 110 | 31996 | 27 | 242 | 50 |
| 9000 | 33809 | 100 | 120 | 36102 | 31 | 257 | 58 |
| 9500 | 38155 | 100 | 120 | 40551 | 31 | 280 | 62 |
| 10000 | 43292 | 110 | 130 | 46746 | 31 | 280 | 62 |
| 50000 * | > 90000 | 470 | 651 | > 90000 | 160 | 3074 | 351 |
| 100000 * | > 90000 | 951 | 1412 | > 90000 | 250 | 5257 | 703 |
The following figure introduces the values of the
table in graphical format.
FAMOUS: the lines marked with * will not come considered in the
graphical rappresentazione
The next figure extension the same diagram but with the axis of the times (y) in logaritmica scale:
Conclusions
The solution 1 (normal concatenation of stringhe) turns out to be onerosa,
with a esponenziale increase of the times of
execution to increasing of the dimension of
tightens manipulated.
The solution 2 (Response.Write) does not turn out
always possible as an example (in case the scope of
the concatenation is not to send of the result to the client), seppur
offers elevated performances.
Solution 3 (I use of Array)
allows the same potentialities of the normal concatenation of stringhe
but it turns out very more efficient, allowing optimal and constant performances also
to increasing of the dimensions of tighten dealt.
It turns out to you are independent from the language
(VBScript or JScript) used