Tip:
Highlight text to annotate it
X
Progeneric’s Parallel Template Library (or PTL) is a generic and parallel programming
library for .NET and Java developers. PTL’s Array and Iterator Algorithms components offer
parallel versions of many useful algorithms, which take advantage of multicore processors
to greatly improve their performance.
In this video, we’ll demonstrate the performance of PTL’s Sort and Reverse algorithms. We’ll
use the .NET List and PTLArray containers for our tests because they are both based
on contiguous native arrays and will give us a fair comparison.
In our tests, both containers are filled with MapEntry values (which are key, value pairs).
The size of a MapEntry value is 16 bytes (8 bytes for the key and 8 bytes for the value).
We also use the MapEntry data type across other demos for consistency to make it easier
to compare results.
We chose to use the Sort and Reverse operations because they are part of the .NET List implementation.
PTL containers only implement basic functions (such as Add, Remove, etc.). All other complex
operations, such as Sort and Reverse, are implemented in the PTL Algorithms component.
The functions in the PTL Algorithms component operate on a range of elements and can be
used with the PTL Containers component.
During this demo, the demo application will be restarted after each test to run each test
independently and get a fair comparison.
Our demo application is executed on a system with one Intel Core i7 processor with 4 physical
cores, or 8 logical cores with hyperthreading, and 32 GB of memory.
Previously, we filled an array with one billion numbers from 0 to 1 billion – 1, randomly
shuffled them and stored them to a file. We’ll use this file to load both the .NET List and
PTLArray objects, so we can compare the Sort results using the same data.
Let’s load 1 billion elements into a .NET List object. We’ll fast forward to when
the Load operation has finished.
Now, let’s run the Sort operation of the .NET List class. Again, we’ll fast forward
to when the Sort has finished. It finished in 4 minutes and 8 seconds with an average
speed around 4,032,000 elements per second.
While we still have the list in memory, let’s run the Reverse operation. We’ll fast forward
to when the Reverse is done. It finished in 1 minute and 49 seconds.
Next, we load the same 1 billion elements into a PTLArray object. We’ll fast forward
to when the Load operation has finished.
PTLArray is the only PTL container that can be used with both the Iterator Algorithms
and the Array Algorithms components. PTLArray has a property called Data that exposes the
underlying native array, so it can be used with the Array Algorithms component for faster
performance, which is what we’ll use in this demo.
Now, let’s run the Sort operation from the SortOper class of the PTL Array Algorithms
component. We’ll fast forward to when the Sort is done. It finished in 3 minutes and
40 seconds with an average speed around 4,545,000 elements per second, which is 1.1 times faster
than the Sort operation of the .NET List.
While we still have the PTL container in memory, let’s run the Reverse operation. It finished
in 2 seconds, which is 54 times faster than the Reverse operation of the .NET List. The
Reverse algorithm, when implemented correctly, is very fast because the algorithm itself
is very cache-friendly.
PTL differs from .NET because it also offers parallel versions of many algorithms, including
Sort and Reverse.
We restarted the demo application again, and we’ll load the same 1 billion elements into
a PTLArray. Again, we’ll fast forward to when the Load has finished.
Now, we’ll run the parallel version of PTL’s Sort algorithm. We’ll fast forward to when
the Parallel Sort has finished. It took 55 seconds with an average speed around 18 million
elements per second.
Finally, let’s run the PTL parallel Reverse. It finished in only 1 second.
Let’s plot the results. PTL’s Parallel Sort is 4.5 times faster than the sequential
Sort operation of the .NET List. And PTL’s Parallel Reverse is 109 times faster than
the sequential Reverse of the .NET List.
PTL’s Algorithms are well designed to process large datasets. First, we carefully optimized
all of PTL's sequential algorithms. Then, we worked *** our parallel algorithms
to obtain the best possible performance improvement over their sequential counterparts.
PTL offers many more containers and algorithms with excellent parallel performance. Click
here to download free trials of all PTL components. You can also learn more about PTL on our website,
where you can read its documentation and view more demos and code examples.