Visual Basic.NET - CONTAR EL TIEMPO TRANSCURRIDO DE UN BUCLE

 
Vista:

CONTAR EL TIEMPO TRANSCURRIDO DE UN BUCLE

Publicado por David (15 intervenciones) el 07/02/2008 15:51:27
Que tal amigos,

quisiera saber si alguien me puede ayuda, necesito contar el tiempo transcurrido desde el inicio de un ciclo for o while no importa hasta su fin.
ejemplo:

tiempo_inicial
tiempo_final

for i = 0 to 100000
n = n+1
end for

yo se q para sakar el tiempo transcurrido es tfinal - finicial obvio, solo que como hacerlo en VB.

De antemano gracias por la ayuda
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

RE:CONTAR EL TIEMPO TRANSCURRIDO DE UN BUCLE

Publicado por kryptic (19 intervenciones) el 07/02/2008 18:39:17
El codigo te regresa el tiempo transcurrido en segundos

Private Sub btnCalcular_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcular.Click
Dim n As Integer = 0
Dim dteInicio As Date = Nothing
Dim dteFinal As Date = Nothing
Dim lngTiempoTranscurrido As Long = 0

dteInicio = DateTime.Now

For i As Integer = 0 To CType(txtNumeroCiclos.Text, Integer)
n += 1
Next

dteFinal = DateTime.Now

lngTiempoTranscurrido = DateDiff(DateInterval.Second, dteInicio, dteFinal)

lblTiempoTranscurrido.Text = "Tiempo transcurrido -> " & lngTiempoTranscurrido & " segundos"
End Sub

saludos, suerte!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE2:RE:CONTAR EL TIEMPO TRANSCURRIDO DE UN BUCLE

Publicado por c3poy2k (15 intervenciones) el 07/02/2008 18:55:44
gracias te agradezco por el codigo


solo que aunque meta una cantida de 99999999 de tope del ciclo por ejemplo, me devuelve "0" segundos no tienes idea de como contar los MILISEGUNDO.


gracias
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

RE:RE2:RE:CONTAR EL TIEMPO TRANSCURRIDO DE UN BUCL

Publicado por kryptic (19 intervenciones) el 07/02/2008 22:43:53
Private Sub btnCalcular_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcular.Click
Dim n As Integer = 0
Dim lngInicio As Long = 0
Dim lngFinal As Long = 0
Dim lngTT As Long = 0

lngInicio = getMilisegundos(DateTime.Now)

For i As Integer = 0 To CType(txtNumeroCiclos.Text, Integer)
n += 1
Next

lngFinal = getMilisegundos(DateTime.Now)

lngTT = lngFinal - lngInicio

lblTiempoTranscurrido.Text = "Tiempo transcurrido -> " & lngTT & " milisegundos"

End Sub

Private Function getMilisegundos(ByVal fecha As Date) As Long
Dim respuesta As Long = 0
Dim dteFechaAux As Date = New Date(1970, 1, 1, 0, 0, 0, 0)

respuesta = DateDiff(DateInterval.Second, dteFechaAux, fecha) * 1000 + fecha.Millisecond

Return respuesta
End Function

saludos suerte !!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar