Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Dictionary speed example

  1. #1
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Dictionary speed example

    Hi all.
    Here a script that will give you an idea of the speed of a Dictionary.
    Speed is very processor/memory dependant so can give very different results on different machines.
    [code=thinbasic] USES "Dictionary"
    uses "FILE"

    '-----------------------------------------------------------------------------
    'Variable declaration
    '-----------------------------------------------------------------------------
    Dim T0, T1, T2, T3, T4, T9 AS quad

    DIM MaxKeys AS LONG VALUE 10000
    DIM Counter AS LONG
    DIM tmpData AS STRING
    DIM Message AS STRING
    DIM tFormat AS STRING VALUE "#0"
    dim KeyFound as long
    dim NotFoundKeys as long
    '-----------------------------------------------------------------------------
    'Confirm script execution
    '-----------------------------------------------------------------------------
    Message = "This program will test Dictionary speed.\n"
    Message += "" & MaxKeys & " keys/data pair will be added to a dictionary\n"
    Message += "All keys will be searched back.\n"
    Message += "Please press Yes to go on, NO to Stop\n"

    DIM lResult AS LONG = MSGBOX(0, Message, %MB_YESNO, "Continue?")
    IF lResult <> %IDYES THEN
    STOP
    END IF


    '------------------------------------------------------------------
    ' Dictionary creation
    '------------------------------------------------------------------
    T0 = GetTickCount '---Start timer for Dictionary creation

    '---Define a LONG that will hold a reference to a new dictionary
    DIM testDict AS LONG

    '---Create a new dictionary with 1000 unique single buckets
    TestDict = Dictionary_Create(MaxKeys * 2, %true)

    '------------------------------------------------------------------
    ' Dictionary add keys
    '------------------------------------------------------------------
    T1 = GetTickCount '---Start timer for Dictionary fill

    '---Here the key name will be computer using KEY followed by the counter
    '---So dictionary will contain the following keys: KEY000001, KEY000002, ..., KEY010000, KEY009999
    '---Random data will be associated with every key
    for Counter = 1 to MaxKeys
    Dictionary_Add(testDict, "KEY" & format$(Counter, "000000"), repeat$(rnd(100, 1000), chr$(rnd(0,255))) )
    next

    '------------------------------------------------------------------
    ' Dictionary search keys
    '------------------------------------------------------------------
    T2 = GetTickCount '---Start timer for Dictionary search

    for Counter = 1 to MaxKeys
    KeyFound = Dictionary_exists(testDict, "KEY" & format$(Counter, "000000") )
    if KeyFound = %FALSE then incr NotFoundKeys
    next

    '-----------------------------------------------------------------------------
    ' Stop clock and show results with some internal counters
    '-----------------------------------------------------------------------------
    T9 = GetTickCount

    Message = "Test results:" & $CRLF
    Message += " - number of key/data pairs " & $tab & $tab & FORMAT$(MaxKeys) & $CRLF
    Message += " - time to create dictionary " & $tab & $tab & FORMAT$(T1 - T0, tFormat) & " msec." & $CRLF
    Message += " - time to add all keys into the dictionary " & $tab & FORMAT$(T2 - T1, tFormat) & " msec." & $CRLF
    Message += " - time to search all keys into the dictionary" & $tab & FORMAT$(T9 - T2, tFormat) & " msec." & $CRLF
    Message += repeat$(80, "-") & $CRLF
    Message += "Total execution time" & $tab & $tab & $tab & FORMAT$(T9 - T0, tFormat) & " msec." & $CRLF
    Message += "Number of keys inside dictionary:" & $tab & $tab & Dictionary_Count(testDict) & $CRLF
    Message += "Number of keys not found during search:" & $tab & NotFoundKeys & $CRLF
    MSGBOX(0, Message)

    '---Remove the whole dictionary and all its keys and data from memory
    Dictionary_Free(TestDict)
    [/code]

    Attached see equivalent script file.
    Attached Images Attached Images
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  2. #2

    Re: Dictionary speed example

    Thanks for example.
    Didn't work at first; errored on following line:

    TestDict = Dictionary_Create(MaxKeys * 2, %TRUE)

    Changed it to:

    TestDict = Dictionary_Create(MaxKeys * 2)

    Then I realised I have not got latest update! Doh!
    Anyway got it to work by 'remming' lines with new keywords.


    catventure.
    http://tab.thinbasic.com - Home Of The ThinBasic Adventure Builder Project. (Interactive Fiction/Text Adventure Maker)

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Dictionary speed example

    Yes, things change very quicly here
    You always need latest preview version even if you already downloaded it just 5 minutes before

    New flag in Dictionary_Create tells to ignore key letter case so you do not need to worry about case sensitivity.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Dictionary speed example

    Hi,

    speed is really nice,
    did you run it on your Core Duo machine ?

    On my traditional PC I am just 2 and bit times slower,
    for seeking even better than that.
    So I'm quite happy. Duron has awaken on the spring


    Bye,
    Petr
    Attached Images Attached Images
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #5
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: Dictionary speed example

    Petr, your create time is 0 msec? I thought perhaps it was 3 digits and not showing, but then we would see the second digit, so it is a mystery. Both Eros and I had 16 ms create times.

    I just remembered I ran across this sort of index key pair before, it was while tinkering with SQL and PHP. I forgot what they called it, but I know it was useful when I was playing with it.

    I am sure this will be very useful for situations like that.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  6. #6
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Dictionary speed example

    kryton,

    my Pc is living organism
    It is very common I get 0 ms in creation stuff, reason could be that WinME has gettickcount somehow imprecisely implemented.

    Bye,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  7. #7

    Re: Dictionary speed example

    Here is the result of my pc:
    Attached Images Attached Images

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Dictionary speed example

    Has you can see results are really good.
    Consider that 80% of the time is taken by thinBasic parser and not by the Dictionary itself to store or find elements.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  9. #9
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: Dictionary speed example

    it is fast as most things in thinBasic are!!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  10. #10
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Dictionary speed example

    Imagine what a normal computer can do in terms of real calculation.
    And now imagine what a computer could do if all big software developers would stop a little bit their time to market "devil" spending a bit more time on their software optimization rather than developing new wrappers working on already big piles of wrappers.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Page 1 of 2 12 LastLast

Similar Threads

  1. Dictionary example
    By Petr Schreiber in forum Dictionary module
    Replies: 12
    Last Post: 22-04-2007, 12:59

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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