Speed Tests for Lists

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. We receive a few cents from each purchase.   Thanks.


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

Problem Description

Here is a program to the list creation and retrieval speed for standard TStringList  the DFF integer equivalent, TIntList.  Speed can be compared under multiple Delphi versions using the same source code.   

Background & Techniques

Some time ago, a fellow working on a Chess solver wrote asking about finding the position (rank) in a list of possible chess piece arrangements for 3 to 6 chess pieces.  Additionally, given a rank, find the corresponding chess piece configuration. I don't believe that we ever really connected on the approach; he seemed to think that there was an algorithmic way to generate these values but it seemed to me that building enumerated lists of valid positions would be required.   In any event, the question led to thus investigation of relative building and retrieval speeds for large stringlists and whether the DFF integer lists would be faster.  They are.

This program runs timing tests for two list types: the standard TStringlist Delphi type and DFF TIntList type which has most TStringList methods but with 64 bit integer keys.

Each test builds the specified number of random records  (Nbr_Entries) of the specified length and then randomly retrieve NbrEntrie/2  records with a couple of different  strategies.  Multiple trials can be run with a single button click and results are displayed.

From my testing, I have concluded that the Delphi 7 version of this program populates an integer list 30 times faster than for a string list of the same size. It  also randomly retrieves integer records 2 or 3 time faster than string records.

When the program is compiled under Delphi XE, string lists are built 2 or 3 times faster than in Delphi 7. Integer lists have exactly the same code under XE are built at about the same speed as under D7 and are therefore "only" about 10 times faster than string lists. Random retrievals of string list records in XE are also several times faster than string list records under Delphi 7. 

From the programmer's perspective, there are several point worth mentioning:

  • To compile the code under Delphi XE, I changed the project name to SpeedTest_XE but left the unit name as U_Speedtest.  This avoided having to keep two versions synchronized as development proceeded.   The Delphi 7 version of the project was changed to Speedtest_Delphi7 for consistency.
  •  Along the same line, the original code was largely duplicated for the Stringlist test button and the Integer List button.  I moved the duplicated code to procedures (Serup, BuildList, SearchList, and ReportResults) and pass a Listtype parameter ( and "S" or "I" character) to last three so that operations are performed on the appropriate list type
  • The Now function returns the current system time in TDateTime format and is convenient in many occasions for timing operations   (StartTime:=Now; {do something} RunTimeSeconds:=SecsPerDay*(Now-StartTime);).  However the resolution of this clock is low, about 17 milliseconds as I recall.  For times of a few milliseconds, start and end times returned may be identical giving runtimes of zero. The happened for timing small integer list size tests in this program  so i switched all timing to use the system Performance Counter which typically provides microsecond resolution.  Two procedures are required to use this timer: QueryPerformanceFrequency returns the counts per second rate of the performance counter and QueryPerformanceCounter returns the current performance counter value.   The difference between two calls to the QueryPerformanceCounter divided by the counter frequency will return the time in seconds.
  • Large numbers are easier to read when formatted with commas (or decimal points where that is the thousands separator).  Unfortunately, the format string for this only formats floating point numbers.  The common way to format integers with thousands separators is to use  '%.0n' in the format string and use it to to display the integer  value + 0.0.  Adding 0.0 will cause Delphi to convert the integer to floating point which %.0n will then display as an integer with thousands separators.                

.  

 Running/Exploring the Program 

Suggestions for Further Explorations

???
 
Created: October 11, 2014

Modified: July 25, 2016

 
  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2017, Gary Darby    All rights reserved.