Results 1 to 28 of 28

Thread: [FACT] - Delphi Faster Then VB!

Threaded View

  1. #1

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253

    [FACT] - Delphi Faster Then VB!

    Article: Click Here

    Extract:

    Benchmarks

    Delphi's superior performance over Visual Basic becomes
    immediately apparent when running a few simple benchmarks.
    Consider the following examples, where a database is filled with
    items of text representing lastname, firstname, phone and street
    information. The phone number field is filled with consecutive
    integers, then the database is re-read and filled with a global
    array of integers from the phone number field. Finally, the
    global array is sorted to become reverse-ordered using a
    comparatively slow bubble sort algorithm.

    Similar code can be written in both Delphi and Visual Basic, with
    the stages of the benchmarks summarized in the following code
    fragments:



    VB - Fill
    ---------
    Sub btnFill_Click ()
    Dim k As Integer
    MaxArray = EdArraySize.Text
    For k = 1 To MaxArray
    Data1.Recordset.AddNew
    Data1.Recordset("LastName") = "Smith " + Str(k)
    Data1.Recordset("FirstName") = "Joe " + Str(k)
    Data1.Recordset("Phone") = Str(k)
    Data1.Recordset.Update
    Next k
    Data1.Recordset.MoveLast
    End Sub

    VB - Read
    ---------
    Sub btnSearch_Click ()
    Dim k As Integer
    Dim n As Integer
    Dim s As String
    Data1.Recordset.MoveFirst
    For k = 1 To MaxArray
    s = edPhone.Text
    n = Val(s)
    Call AppendArray(k, n)
    Data1.Recordset.MoveNext
    Next k
    End Sub

    VB - Sort
    ---------
    Sub btnSort_Click ()
    Dim j As Integer
    Dim k As Integer
    Dim tmp As Integer
    For j = 1 To MaxArray - 1
    For k = 1 To MaxArray - j
    If GlobArray(k) < GlobArray(k + 1) Then
    ' Swap GlobArray[k+] with GlobArray[k] ...
    tmp = GlobArray(k + 1)
    GlobArray(k + 1) = GlobArray(k)
    GlobArray(k) = tmp
    End If
    Next k
    Next j
    End Sub


    Delphi - Fill
    -------------
    procedure TForm1.Button4Click(Sender: TObject);
    var
    k,err: integer;
    s: string;
    begin
    val(edDBsize.Text,maxArray,err);
    for k:=1 to maxArray do
    with Table1 do
    begin
    str(k,s);
    Append;
    FieldByName('Lastname').AsString := 'NewGuy'+s;
    FieldByName('Firstname').AsString := 'Paul'+s;
    FieldByName('Phone').AsString := s;
    Post;
    end
    end;

    Delphi - Read
    -------------
    procedure TForm1.btnSearchTestClick(Sender: TObject);
    var
    s: string;
    n,err,k: integer;
    begin
    val(edDBsize.Text,MaxArray,err);
    Table1.First;
    for k:=1 to MaxArray do
    begin
    s := DBedPhone.EditText;
    val(s,n,err);
    AppendArray(k,n);
    Table1.Next;
    end;
    end;

    Delphi - Sort
    -------------
    procedure TForm1.btnSortArrayClick(Sender: TObject);
    var
    j,k,tmp: integer;
    begin
    for j:=1 to MaxArray-1 do
    for k:=1 to MaxArray-j do
    if GlobArray[k] < GlobArray[k+1] then
    begin
    { Swap GlobArray[k+] with GlobArray[k] ... }
    tmp := GlobArray[k+1];
    GlobArray[k+1] := GlobArray[k];
    GlobArray[k] := tmp;
    end;
    end;

    Benchmark Results

    The following table shows the results for database tables ranging
    in size from 100 to 4000 records. The test stages Fill, Read and
    Sort correspond the code sections described on the previous
    pages.
    (All benchmark times are in seconds.)

    D = Delphi
    FL = Fill
    RD = Read
    X = x Sort
    ST = Sort

    -----------------------------------------------------------------
    # D VB D VB D X VB D X Total VB
    items
    FL FL RD RD ST ST Total Total
    -- -- -- -- -- -- ----- -----
    100 2 2 30 1 0 0 0 2 1.5 3

    1000 16 70 6 23 1 22 22 23 5 115

    2000 33 141 12 46 4 21 84 49 5.5 271

    3000 50 227 17 69 8 23.6 189 76 6.4 485

    4000 67 297 23 77 15 19.6 294 106 6.3 668
    -----------------------------------------------------------------


    As can be seen from the results, the resulting Delphi-generated
    code outperformed the Visual Basic routines, especially in
    code-bound portions such as the Sort stage, by about 20 times
    faster. Delphi's database access functionality was also shown to
    be about five times more efficient than that of the Visual Basic
    code.


    I always knew i could prove Delphi to be faster then VB, and not my words, but as the article says, far more SUPERIOR

    Its also worth noting:

    * Pascal is a more powerful and structured language than
    Basic.

    * Object Pascal is a true object-oriented programming
    language, providing the benefits of inheritance,
    encapsulation and polymorphism;

    * Pascal is a compiled language, ensuring high-performance
    executables;

    * The organization of files as DCUs provides a cleaner
    mechanism for creating libraries of reusable code (see
    Shared Event Code);

    * Object Pascal utilizes the world's fastest commercial
    compiler technology;

    * Object Pascal support in-line assembler code for maximum
    performance;
    Last edited by Madboy; Aug 14th, 2005 at 06:01 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width