Sortierzeit herausfinden und vergleichen

  • Hallo,
    ich bins mal wieder!


    HAbe verschiedene Sortieralgorythmen geschrieben und wollte jetzt mal testen welcher schneller ist! Gibts da ne möglichkeit die Zeiten herauszufinden die die Scripte brauchen, um ein Array zu Sortieren??


    Würde mich über Antwort freuen


    Schönen Tag


    Esc

    [img align=left]mitglied.lycos.de/escheworld/euros.php[/img]

  • Es gibt den Now-Operator in NotesDateTime, analog zu @Now in der Formel-Sprache. Damit kannst du Start und Ende ausgeben lassen

    Life is not a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming "Wow, what a ride!!! :evil:
    Beschleunigung ist, wenn die Tränen der Ergriffenheit waagrecht zum Ohr hin abfliessen - Walter Röhrl

  • sowas in der Art hab ich mir schon gedacht! Hatte es bis jetzt so


    EDIT: GOTT Bin ich ..... blind ^^

    Set timeStart = New NotesDateTime(Now())
    Set TimeEnde = New NotesDateTime(Now())
    Dif = Cstr(timeEnde.TimeDifference(TimeStart))


    Dachte es gibt eventuell ne schönere Methode das zu realisieren ;)


    Jetzt rechnet er mir es in sekunden aus! Bräuchte aber ja noch die Millisekunden! Wie komme ich da ran?

    [img align=left]mitglied.lycos.de/escheworld/euros.php[/img]

  • hmm, wenn mich nicht alles täuscht, ist sekunden*1000=millisekunden?

    Life is not a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming "Wow, what a ride!!! :evil:
    Beschleunigung ist, wenn die Tränen der Ergriffenheit waagrecht zum Ohr hin abfliessen - Walter Röhrl

  • hab mich vielleicht ein bisschen falsch ausgedrückt!


    Bis jetzt kommt ja so nen Ergebnis raus: 1 Sekunde


    Brauch das aber ja so 1,XXXXXX Sekunden! Und die XX mit Millisekunden aufgefüllt bzw gleich in Millisekunden ausrechnen lassen sonst kann ich das ziemlich schlecht vergleichen ;) :roll:

    [img align=left]mitglied.lycos.de/escheworld/euros.php[/img]

  • war nicht immer Sekunde * 1000 = millisekunde???
    *Da weiss man erst, was einem fehlt wenn man kein vernuenftiges Mathematikstudium hatte :D
    Aber kann das in Notes einfach umgerechnet werden?? Interessant sind bestimmt die Zeiten < 1 sec..einfach die ganzen Sek, umzuwandeln in Millisekunden war wohl nicht das Ziel, oder irre ich?

  • so dank hilfe von jemaden hab ichs jetzt endlich


    für alle die es interessiert


    Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long


    ende = GetTickCount()
    start = Get TickCount()
    Msgbox Cstr(ende - start)


    Ne andere möglichkeit ist mir net eingefallen....

    [img align=left]mitglied.lycos.de/escheworld/euros.php[/img]

  • Im 5er Public AddressBook Maske Gruppe gibt es den schönen Button "Mitgliedernamen sortieren", hinter dem sich eine recht ausgefeilte, und vor allem für ALLE Sorten von Variablen (Text, Datum, Zahlen) verwendbare Sortierroutine verbirgt. Die reicht mir für meine Anwendungen eigentlich immer. Hier der Code davon:


    Public Function QuickSort(sArray As Variant)
    Dim sA() As Variant
    Dim j As Long
    Dim bottom As Long
    Dim top As Long
    bottom = Lbound ( sArray )
    top = Ubound ( sArray )
    Redim sA( bottom To top ) As Variant
    For j = bottom To top
    sA ( j ) = sArray ( j )
    Next
    ' DoQS does a QuickSort if the Sublist is longer than 10 elements
    ' Thus, when DoQS finishes, all elements are within 10 spots of their correct location.
    ' For lists that are close to being in order, an Insertion Sort is much faster than a QuickSort, so we
    ' run through the whole thing once doing an Insertion Sort to finish tidying up the order.
    Call DoQS( sA, bottom, top )
    Call DoInsertSort ( sA, bottom, top )
    SortedArray = sA
    End Function


    Sub DoQS( sA() As Variant, bottom As Long, top As Long )
    ' Called by QuickSort
    ' Uses Public variable sA (array of string)
    Dim length As Long
    Dim i As Long
    Dim j As Long
    Dim Pivot As Long
    Dim PivotValue As Variant
    Dim t As Variant
    Dim LastSmall As Long
    length = top - bottom + 1

    ' Only do the QuickSort if the sublist is at least 10 items long
    If length > 10 Then
    ' Pivot is chosen approx. halfway through sublist.
    ' This gives us best speed if list is almost sorted already, and is no worse than any
    ' other choice if the list is in random order.
    Pivot = bottom + (length \ 2)

    ' Move PivotValue out of the way
    PivotValue = sA( Pivot )
    sA ( Pivot ) = sA ( bottom )
    sA ( bottom ) = PivotValue

    ' LastSmall is the location of the last value smaller than PivotValue
    LastSmall = bottom
    For i = bottom + 1 To top
    If sA ( i ) < PivotValue Then
    LastSmall = LastSmall + 1
    t = sA ( i )
    sA ( i ) = sA ( LastSmall )
    sA ( LastSmall ) = t
    End If
    Next

    ' Move the PivotValue back
    t = sA ( LastSmall )
    sA ( LastSmall ) = sA ( bottom )
    sA ( bottom ) = t
    Pivot = LastSmall

    ' Now sort each side
    Call DoQS ( sA, bottom, Pivot - 1 )
    Call DoQS ( sA, Pivot + 1, top )
    End If

    End Sub


    Public Function QuickSort(sArray As Variant)
    Dim sA() As Variant
    Dim j As Long
    Dim bottom As Long
    Dim top As Long
    bottom = Lbound ( sArray )
    top = Ubound ( sArray )
    Redim sA( bottom To top ) As Variant
    For j = bottom To top
    sA ( j ) = sArray ( j )
    Next
    ' DoQS does a QuickSort if the Sublist is longer than 10 elements
    ' Thus, when DoQS finishes, all elements are within 10 spots of their correct location.
    ' For lists that are close to being in order, an Insertion Sort is much faster than a QuickSort, so we
    ' run through the whole thing once doing an Insertion Sort to finish tidying up the order.
    Call DoQS( sA, bottom, top )
    Call DoInsertSort ( sA, bottom, top )
    SortedArray = sA
    End Function

  • Das beleidigte Gesicht mit "AHA" als einzigem Kommentar fand ich schon ärgerlich.


    Sorry, ich hatte zweimal Quicksort und keinmal DoInsertSort eingefügt. Hier der fehlende Teil:


    Sub DoInsertSort ( sA() As Variant, Byval bottom As Long, Byval top As Long )
    Dim i As Long
    Dim x As Long
    Dim v As Variant
    Dim Found As Integer
    For i = bottom+1 To top
    x = i
    v = sA (i )
    Do While (sA(x-1) > v)
    sA ( x ) = sA ( x-1 )
    x = x - 1
    If x=0 Then
    Exit Do
    End If
    Loop
    sA (x) = v
    Next
    End Sub

  • Das tut mir leid; wollte doch nicht Dein stolzes Programmiererherz kraenken. Es war aber kein beleidigtes Gesicht sondern ein fragendes. Weil...es war gar kein Sortieralgorythmus gesucht worden. Deshalb das fragende Gesicht.

  • Wenn jemand danach sucht, wie zeitintensiv sein selbstgeschriebener Sortieralgorithmus ist, dann ist derjenige vermutlich schon auf der Suche nach einem guten Algorithmus. Und dann kann er zum Vergleich ja einmal die vortgegebenen Algorithmen ausprobieren.


    Wenn sein selbstgeschriebener Algorithmus dann schneller ist, bin ich bestimmt auch gerne Interessent und Abnehmer, denn gerade bei einer solchen Standardprozedur ist das Bessere bekanntlich der Feind des Guten.


    Der von Lotus bereitgestellte Algorithmus ist aber schon vergleichsweise gut. Das Ergebnis des Vergleichs interessiert mich.