Recent

Author Topic: How is compared for Lazarus from speed to C programming ?  (Read 6363 times)

LV

  • Sr. Member
  • ****
  • Posts: 427
Re: How is compared for Lazarus from speed to C programming ?
« Reply #15 on: August 12, 2025, 09:43:10 am »
Here are two important points to consider:

1. Flagship C or C++ compilers offer more built-in optimization capabilities than FPC.
2. Highly optimized libraries, such as MKL and OpenBLAS, are written in C or assembly language.

Using FPC requires additional effort to achieve performance comparable to C, C++. Despite this, there are compelling reasons to use FPC and Lazarus.  :)

440bx

  • Hero Member
  • *****
  • Posts: 6556
Re: How is compared for Lazarus from speed to C programming ?
« Reply #16 on: August 12, 2025, 11:00:51 am »
Despite this, there are compelling reasons to use FPC and Lazarus.  :)
As ALLIGATOR mentioned, compilation speed is one of the primordial reasons.

I'd add that FPC's implementation of Pascal makes it reasonably easy to implement complex algorithms that are still understandable.  This is something that very often cannot be said about other "optimizing compilers" ;)

OTH, a language that doesn't get an update in over 4 years is going to have real problems attracting new blood.

FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 456
  • I use FPC [main] 💪🐯💪
Re: How is compared for Lazarus from speed to C programming ?
« Reply #17 on: August 12, 2025, 11:18:39 am »
Well, I don't consider FPC separately from Lazarus. Of course, they are separate projects, but my choice of Pascal was initially due to the fact (since Delphi 7) that it was very easy to create GUI applications in it, and now it is also easy to do in Lazarus.

If there were no GUI part, it would probably make Pascal much less attractive to me, and it might be easier to switch to mainstream languages...
I may seem rude - please don't take it personally

Thaddy

  • Hero Member
  • *****
  • Posts: 19420
  • Glad to be alive.
Re: How is compared for Lazarus from speed to C programming ?
« Reply #18 on: August 12, 2025, 11:40:54 am »
In the past I worked with GCJ but that seems abandoned.
Any "programmer" that knows only one programming language is not a programmer

korba812

  • Sr. Member
  • ****
  • Posts: 486
Re: How is compared for Lazarus from speed to C programming ?
« Reply #19 on: August 12, 2025, 12:02:55 pm »
Lazarus is speed as C programming ? Or more fast than C? Or more less than C?
I would say it depends on the program. For example, I can write an "address book" program faster in Lazarus/FPC than in C. ;)

threedslider

  • New Member
  • *
  • Posts: 29
Re: How is compared for Lazarus from speed to C programming ?
« Reply #20 on: August 12, 2025, 01:24:43 pm »
Depends on the C .

Yes it depends on C, if it is poorly built it is a penalty for speed I also think it is the same for Lazarus I, right ?.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12947
  • FPC developer.
Re: How is compared for Lazarus from speed to C programming ?
« Reply #21 on: August 12, 2025, 01:27:34 pm »
Depends on the C .

Yes it depends on C, if it is poorly built it is a penalty for speed I also think it is the same for Lazarus I, right ?.

Yes, but it is not black-white. Those last bits of performance are the hardest to get in any language, and just because it is theoretically possible, it won't mean that you will be able to unlock them in an application of your own. (and even less so in a finite time)

threedslider

  • New Member
  • *
  • Posts: 29
Re: How is compared for Lazarus from speed to C programming ?
« Reply #22 on: August 12, 2025, 01:30:50 pm »
Code: Text  [Select][+][-]
  1. Java:         Total execution time: 200ms
  2. Pascal (-O3): Total execution time: 22657ms
So java is around a factor 100 faster.

I hear that Java from speed is compared to C++ and in some certain case  it is more faster than C++ too...  :o

So yeah, Java can easily be faster than FPC

 :o

LV

  • Sr. Member
  • ****
  • Posts: 427
Re: How is compared for Lazarus from speed to C programming ?
« Reply #23 on: August 12, 2025, 03:07:22 pm »
Code: Text  [Select][+][-]
  1. Java:         Total execution time: 200ms
  2. Pascal (-O3): Total execution time: 22657ms
So java is around a factor 100 faster.

I hear that Java from speed is compared to C++ and in some certain case  it is more faster than C++ too...  :o


It seems like we are playing a game of how to write the slowest code.

Code: C++  [Select][+][-]
  1. #include <iostream>
  2. #include <chrono>
  3.  
  4. class TTest {
  5. private:
  6.     int adder;
  7. public:
  8.     TTest(int a) : adder(a) {}
  9.     int Add(int i) {
  10.         return i + adder;
  11.     }
  12. };
  13.  
  14. int main() {
  15.     using namespace std::chrono;
  16.  
  17.     auto start = duration_cast<milliseconds>(
  18.         steady_clock::now().time_since_epoch()
  19.     ).count();
  20.  
  21.     long long i = 0;
  22.     int accum = 0;
  23.  
  24.     while (i < 1000000000LL) {
  25.         TTest* t = new TTest(static_cast<int>(i));
  26.         accum = t->Add(accum);
  27.         delete t;
  28.         ++i;
  29.     }
  30.  
  31.     auto end = duration_cast<milliseconds>(
  32.         steady_clock::now().time_since_epoch()
  33.     ).count();
  34.  
  35.     std::cout << "Total execution time: " << (end - start) << "ms\n";
  36.     std::cin.get();
  37.     return 0;
  38. }
  39.  

Code: Text  [Select][+][-]
  1. Total execution time: 41150ms
  2.  

 8-)

threedslider

  • New Member
  • *
  • Posts: 29
Re: How is compared for Lazarus from speed to C programming ?
« Reply #24 on: August 12, 2025, 03:41:17 pm »
Mine is more faster in C++  :o 8-) :D

Code: C++  [Select][+][-]
  1. #include <iostream>
  2. #include <vector>
  3. #include <chrono>
  4.  
  5. using namespace std;
  6. using namespace std::chrono;
  7.  
  8. const int N = 10'000'000;
  9.  
  10. void benchmark_array() {
  11.     int* arr = new int[N];
  12.  
  13.     for (int i = 0; i < N; ++i)
  14.         arr[i] = i;
  15.  
  16.     auto start = high_resolution_clock::now();
  17.  
  18.     for (int i = 0; i < N; ++i)
  19.         arr[i] = arr[i] * 2 + 1;
  20.  
  21.     auto end = high_resolution_clock::now();
  22.     cout << "Tableau classique : "
  23.         << duration_cast<milliseconds>(end - start).count()
  24.         << " ms" << endl;
  25.  
  26.     delete[] arr;
  27. }
  28.  
  29. void benchmark_vector() {
  30.     vector<int> vec(N);
  31.  
  32.     for (int i = 0; i < N; ++i)
  33.         vec[i] = i;
  34.  
  35.     auto start = high_resolution_clock::now();
  36.  
  37.     for (int i = 0; i < N; ++i)
  38.         vec[i] = vec[i] * 2 + 1;
  39.  
  40.     auto end = high_resolution_clock::now();
  41.     cout << "std::vector       : "
  42.         << duration_cast<milliseconds>(end - start).count()
  43.         << " ms" << endl;
  44. }
  45.  
  46. int main() {
  47.     benchmark_array();
  48.     benchmark_vector();
  49.     return 0;
  50. }
  51.  

Code: Text  [Select][+][-]
  1. Tableau classique : 3 ms
  2. std::vector       : 2 ms
  3.  

threedslider

  • New Member
  • *
  • Posts: 29
Re: How is compared for Lazarus from speed to C programming ?
« Reply #25 on: August 12, 2025, 03:58:34 pm »
If I make the change to  1'000'000'000 it gives us that as it :

Code: Text  [Select][+][-]
  1. Tableau classique : 286 ms
  2. std::vector       : 277 ms
  3.  

Really fast though  :D

Warfley

  • Hero Member
  • *****
  • Posts: 2071
Re: How is compared for Lazarus from speed to C programming ?
« Reply #26 on: August 12, 2025, 05:27:05 pm »
I hear that Java from speed is compared to C++ and in some certain case  it is more faster than C++ too...  :o

...

 8-)
Yes that's my point, some things are really fast in java, much faster than in other languages. That said the C++ example is a bit off here, because in C++ classes can be allocated on the stack, in pascal you can't (except with hacks). While advanced records and objects exist (see last example in that post) its fair to say that usage of classes in fpc is more common than the alternatives. In comparison in C++ usage of heap allocations is relatively rare (except on enterprise C++ maybe) and most classes are constructed on the stack. So in that regard Pascal code you'd spot in the wild is much closer to Java than it is to C++

LV

  • Sr. Member
  • ****
  • Posts: 427
Re: How is compared for Lazarus from speed to C programming ?
« Reply #27 on: August 12, 2025, 05:35:47 pm »
If I make the change to  1'000'000'000 it gives us that as it :

Code: Text  [Select][+][-]
  1. Tableau classique : 286 ms
  2. std::vector       : 277 ms
  3.  

Really fast though  :D

C++ & OpenMP
Code: Text  [Select][+][-]
  1. Tableau classique : 160 ms
  2. std::vector       : 161 ms
  3.  

FPC & TThread
Code: Text  [Select][+][-]
  1. Dynamic Array: 156 ms
  2. ~ std::vector  : 172 ms
  3.  

LV

  • Sr. Member
  • ****
  • Posts: 427
Re: How is compared for Lazarus from speed to C programming ?
« Reply #28 on: August 12, 2025, 05:49:04 pm »
@Warfley, Thanks for your comment.

Thaddy

  • Hero Member
  • *****
  • Posts: 19420
  • Glad to be alive.
Re: How is compared for Lazarus from speed to C programming ?
« Reply #29 on: August 12, 2025, 06:20:58 pm »
@Warfley

Old school objects are. like records, stack allocated and that is one of the reasons I still use them.
E.g.: for stock exchange tickers you need that to keep up, either that or records.
There are no hacks required. That's only when you use classes.

In such cases, Freepascal is very close to Java or stack based C++ classes.

They still maintain OOP behaviour, contrary to records.
« Last Edit: August 12, 2025, 06:34:45 pm by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

 

TinyPortal © 2005-2018