I thought it would be fun to implement a binary search tree in six different languages, not only to show the implementation differences but to also show the memory/CPU performance results.
The results below are based off of a computer running Windows 10 Pro x64 with an Intel Core i7 4770k processor overclocked to 4.5 GHz and with 16 GB of RAM installed.
Generating random array with 2,000,000 values | Filling tree with 2,000,000 nodes | Traversing all 2,000,000 nodes | Peak memory used |
---|---|---|---|
22 ms | 12.86 sec | 128 ms | 53 MB |
Version | Generating random array with 2,000,000 values | Filling tree with 2,000,000 nodes | Traversing all 2,000,000 nodes | Peak memory used |
---|---|---|---|---|
.NET 4.6/C# 4.0 | 25 ms | 13.07 sec | 128 ms | 58 MB |
Generating random array with 2,000,000 values | Filling tree with 2,000,000 nodes | Traversing all 2,000,000 nodes | Peak memory used |
---|---|---|---|
21 ms | 12.2 sec | 126 ms | 70 MB |
Generating random array with 2,000,000 values | Filling tree with 2,000,000 nodes | Traversing all 2,000,000 nodes | Peak memory used |
---|---|---|---|
66 ms | 12.9 sec | 130 ms | 85 MB |
Version | Generating random array with 2,000,000 values | Filling tree with 2,000,000 nodes | Traversing all 2,000,000 nodes | Peak memory used |
---|---|---|---|---|
Python 2.7.10 | 1.9 sec | 98 sec | 750 ms | 377 MB |
Python 3.5.0 | 2.55 sec | 114.23 sec | 828 ms | 220 MB |
Version | Generating random array with 2,000,000 values | Filling tree with 2,000,000 nodes | Traversing all 2,000,000 nodes | Peak memory used |
---|---|---|---|---|
Node.js 5.1.0 | 34.64 ms | 11.06 sec | 89.38 ms | 148 MB |