Originariamente inviato da Baol74
Non ho ben capito!

E' più veloce o più lenta? "L'uso della classe di cui sopra è 40 volte più lenta"

E cosa intendi per scrittura diretta col tag <% ?
ho fatto questo esempio solo per farmi un'idea
1) l'istruzione s &= stringa è assolutamente lenta
2) l'uso della tua classe mi è risultata circa 60 volte più veloce
3) la scrittura diretta nella pagina però è a sua volta circa 40 volte più veloce

prova l'esempio
codice:
<%@ Language=VBScript %>
<%
option explicit

dim s1, s2, i, n, TimeIt1, TimeIt2, StartTime, EndTime

n = 30000

StartTime = timer
s1 = ""
for i = 1 to n
	s1 = s1 & "|1234567890"
next
EndTime = timer
TimeIt1 = EndTime - StartTime


StartTime = timer
Set s2 = new cString
for i = 1 to n
	s2.Append("|1234567890")
next
EndTime = timer
TimeIt2 = EndTime - StartTime





%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>



Tempo1 = <%=TimeIt1%></P>


Tempo2 = <%=TimeIt2%></P>


s1 = <%=s1%></P>


s2 = <%=s2%></P>

<% 
dim TimeIt3
StartTime = timer
for i = 1 to n %>
|1234567890
<%next
EndTime = timer
TimeIt3 = EndTime - StartTime
%>


Tempo3 = <%=TimeIt3%></P>



</BODY>
</HTML>

<%
Class cString
	Private Buffer

	Private Sub Class_Initialize()
		Set Buffer = Server.CreateObject("ADODB.Stream")
		Buffer.Charset = "ISO-8859-1"
		Buffer.Type = 2
		Buffer.Open()
	End Sub

	Public Function ToArray()
	Dim Ar(),i
		Redim Ar(Buffer.Size) 
		Buffer.Position = 0
		For i=0 to Buffer.Size
			Ar(i)=Buffer.ReadText(1)
		Next
		ToArray = Ar
	End Function

	Public Function Clear()
		On error resume next
		Buffer.Close()
		on error goto 0
		Buffer.Open()
	End Function

	Public Sub Append(byRef value)
		Buffer.WriteText(value)
	End Sub

	Public Sub AppendLine(byRef value)
		Buffer.WriteText(value & VbCrLf)
	End Sub

	Public Function GetIndex(Index)
	Dim p
		p = Buffer.Position 
		Seek(Index)
		GetIndex = Read(1)
		Buffer.Position = p
	End Function
	
	Public Function Read(Bytes)
		Read = Buffer.ReadText(Bytes)
	End Function

	Public Sub Seek(Position)
		Buffer.Position = Position
	End Sub

	Public Sub Skip(Value)
		Buffer.Position = Buffer.Position + Value
	End Sub
	
	Public default Function GetBuffer()
		Seek(0)
		GetBuffer = Buffer.ReadText()
	End Function

	Public Function Length()
		Length = Buffer.Size
	End Function

	Private Function MapPath(s)
		Dim Res
		on error resume next
			Res = Server.MapPath(s)
			if err.number<>0 then REs = s
		on error goto 0
		MapPath = Res
	End Function

	Public Sub SaveToFile(FileName,OverWrite)
		FileName = MapPath(FileName)
		If OverWrite=1 then 
			OverWrite=false
		elseif OverWrite=2 then
			OverWrite=true
		End if
		Buffer.SaveToFile FileName,OverWrite
	End Sub

	Private Sub Class_Terminate()
		Buffer.Close()
		Set Buffer = Nothing
	End Sub

End Class

'Un esempio

'Set s = new cString
's.Append(",")
's.Append("Ciao")
's.Append("Test")
'Response.Write(s)


'La classe serve anche (e soprattutto per altri scopi. 
'Ad esempio è possibile accedere alla string come se fosse un Array (Funzione GetIndex) 
'oppure è possibile convertirla in un Array in modo molto veloce 
'(non si utilizza naturlmente il mid. La fiunzione è ToArray()).Seek 
'Consente il posizionamente del puntatore interno. 
'Skip consente il salto caratteri.
'Length è la lungezza (s.length). 
'Clear svuota l'oggetto. 
'AppendLine fa un inserimento del tipo Stranga + VbCrLF. 
'
'Con l'utilizzo di parametri opzionali (in vbscript è possibile usarli) 
'la classe si fa più interessante e completa.



%>