Site icon Learn C++

Brothers are in Fight! Delphi and C++ Builder Comparison in Prime Test

We have released a lot of Prime Number Benchmarks posted in LearnCPlusPlus.org before, Easily Learn To Find Prime Numbers In Modern C++ and Interesting C++ Builder Compiler Counting Prime Number Benchmarks are some of tests, you can find more here with Dev-C++, GNU C/C++, VS Code examples. It is good to test mathematical speed of programming language and we are able to compare same code with other cases in different programming languages.

In this test we will test two brothers, C++ Builder and Delphi on these Prime numbers, both are great programming languages that comes with RAD Studio.

1. System Description

PC setups that we used in tests here is;

OS: Windows 10 64 bit

Setup-1:
Processor AMD Ryzen 7 1800X (3.6 Ghz), 8 Core(s), 16 Logical Processor(s).

Setup-2:
Haswell: Processor Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz, 3601 Mhz, 4 Cores, 8 Logical Processors

Setup-3:
Processor AMD Ryzen 5 3600X 6-Core Processor, 3793 Mhz, 6 Core(s), 12 Logical Processor(s).

2. Calculating Prime Numbers in C++ Builder

C++ Builder includes compilers for Win32, Win64, Android and iOS. C++Builder has both CLANG Enhanced C/C++ Compiler and a Borland C/C++ Compiler. It also features a modern, high-productivity RAD Studio IDE, debugger tools, and enterprise connectivity for to accelerate cross-platform UI development. You can develop GUI based applications easily, as it comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs. There is a free C++ Builder Community Edition that can be used by students, beginners and startups with limitations.
In this test we will use same code we used before in C++ Builder.

Bruneau Babet who is one of major developers in Embarcadero is a great developer as other developers in Embarcadero and he was very helpful on this comparison topic. As a result of discussion there, In C++ Builder, we optimized Prime Time test as below,

cpptest.cpp file which has optimized is_prime() and count_prime() functions,

[crayon-67630f871e2e9693262376/]

test.cpp which links and tests both c++ and delphi/pascal codes

[crayon-67630f871e2f1249613468/]

This below is a build.bat that compiles both Delphi and C++ files and links as test32.exe and as test64exe. Here in compilation we used -ffast-math -Xdriver -mavx parameters with -O2 optimization to compile

[crayon-67630f871e2f3338481304/]

3. Calculating Prime Numbers in Delphi

Delphi is another compiled (non-interpreted) faster programming language which has support to 32 and 64bits on Windows , Android , iOS, Mac-OS and Linux Operating Systems. C++ Builder and Delphi are using RADS IDE and both has VCL and FMX UI Frameworks.

This is Delphi code modified and that we tested,

[crayon-67630f871e2f6985278514/]

4. 32bits and 64bits Results in Delphi and C++ Builder

To compile both cpp and delphi (pas) files;

  1. Run RAD Studio Command Prompt
  2. Go to your project folder which has codes above
  3. run ‘build.bat’ to compile both .pas and .cpp files into test32.exe and test64.exe files
  4. run ‘test32.exe 5’ , here 5 parameter runs 1M tests 5 times
  5. run ‘test64.exe 5’, here 5 parameter runs 1M tests 5 times

Here are the test results on the 1st Setup with AMD Ryzen 7 1800X,

These are the results from Bruneau Babet with Setup-2, HaswellProcessor Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz

These are the results of Intel C++, MS C++, Embarcadero C++ Builder and Delphi from Bruneau Babet with Setup-2, Haswell Processor Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz

WIN64 IntelWIN64 MicrosoftWIN64 EMBWIN64 EMB
C++: 63.5429 msC++: 73.6702 msC++: 72.6415 msPas: 72.1771 ms
C++: 63.9021 msC++: 72.2942 msC++: 73.5697 msPas: 71.8799 ms
C++: 64.2266 msC++: 73.7869 msC++: 73.2985 msPas: 72.5148 ms
C++: 63.5858 msC++: 72.6505 msC++: 72.9837 msPas: 71.1668 ms

And these results below are also from Bruneau Babet with another Ryzen CPU Setup-3, Processor AMD Ryzen 5 3600X 6-Core Processor, 3793 Mhz, 6 Core(s), 12 Logical Processor(s).

[crayon-67630f871e2f7477822563/]

5. Comparison

C++ Builder vs Delphi Fight Finals here, the 32 bits results compared in a table as below,

And 64bits results compared as below,

As a result C++ Builder Wins the 32bits Round with about 3% faster results, and on the 64bits Round Winner is C++ Builder with only about 8% faster results.

6. Conclusion

C++ is one of the fastest programming language and Delphi is also another faster programming language we know, both are non-interpreted (compiled) native programming languages. I personally had tests on pascal codes many years ago (about in 98-2000) and all tests were showing C++ Builder was faster than Delphi, and in this post we found time to test these two awesome programming language again.

In this Fight!,
as a result C++ Builder Wins the 32bits Round with about 3% faster results
and on the 64bits Round Winner is C++ Builder with only about 8% faster results.

Actually, i wasn’t expecting this, i was expecting more difference between them because of my tests done before many years ago.

Here, if we look at the results the latest Delphi is also Winner !! i think because of the improvements in the last decade, it proofs that it is faster and stronger as fast as C++. This shows Delphi has great improvements in compilation during the last years, and it has very good results in 32bits compilation, 64bits compilation is also great.

These results are from runs on single core and do not consider number of cores. In real, this prime number test has few functions on runtime, not means all but i think these tests are enough to give some information about how fast the programming language. There might be more tests including more mathematics, 2D graphics, 3D graphics, GUI elements. I don’t think there will be difference between Delphi and C++ Builder, and not sure about graphics.

We also applied some tests with Intel and Visual C++ compilers on this new optimized Prime Time tests as given above, C++ compilers were had about same results with very small changes.

In conclusion, amazingly these results mean you can use both of these C++ Builder and Delphi programming language in all cases; including heavy mathematics, AI technologies, ML applications, Image Processing, Parallel Programming, Engineering Simulations, Games etc. Probably there will be only 3-8% difference in these tests.

Can we speed up more on both Delphi and C++ Builder? Of course Yes! We just used single core, we have also tested on parallel programming which uses all cores, We can also speed-up these results by using CPU and GPU together. Please keep in touch with LearnCPlusPlus.org.

Get started building powerful apps with C++Builder!

Exit mobile version