Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Faster Delphi RTL with Parallel Arrays and Ordered Dictionaries

faster delphi rtl

While the most relevant new features were in other product areas, there are a few enhancements in the Delphi Run Time Library (o RTL) that we thing is worth pointing out.

New TParallelArray Class

There is a new TParallelArray class in the System.Threading unit that enables running operations like &For and Sort in parallel on Array items. On multi core systems, this can speed them up considerably. How can you use it? This is a simple test case, command line project, which creates two identical arrays and sorts them with the regular single-thread Sort and the new parallel version:
[crayon-6766f9924465d508703851/]
If I run it on my main computer, an Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz , I get the following results, a nice 585% improvement! (output trimmed to milliseconds for readability)
[crayon-6766f99244665551632241/]

New TOrderedDictionary Class

There is also a new TOrderedDictionary class, derived from TDictionary<K,V>, in the System.Generics.Collections unit. An Ordered Dictionary is a dictionary with integrated sorting methods in the dictionary. This makes is simple to have a for in loop navigating the data in a sorted order, and also makes it faster to locate elements. As an example, take a look at the following project which:

[crayon-6766f99244668760015740/]
This is the complete output:
[crayon-6766f9924466a827960139/]

A Few More RTL Enhancements

That’s all for this blog post, hope you’ll be able to start leveraging these and the many other new RTL features added in recent releases in your projects.

Exit mobile version