Recent

Author Topic: Quicksort a string array (Case insensitive or standard)  (Read 4196 times)

avk

  • Hero Member
  • *****
  • Posts: 752
Re: Quicksort a string array (Case insensitive or standard)
« Reply #15 on: September 27, 2020, 07:30:26 pm »
There is another funny question. How many Pascal libraries do you know that are faster than the corresponding C library?

Thaddy

  • Hero Member
  • *****
  • Posts: 14198
  • Probably until I exterminate Putin.
Re: Quicksort a string array (Case insensitive or standard)
« Reply #16 on: September 27, 2020, 07:45:00 pm »
By algorithm ? Almost all string handling.... C cant't handle strings very well and C++ has no built in support for real strings that contain zero's, which makes a quick escape but not a real deal....Specifically string reads are much faster in Pascal, because length is stored...
« Last Edit: September 27, 2020, 07:48:50 pm by Thaddy »
Specialize a type, not a var.

avk

  • Hero Member
  • *****
  • Posts: 752
Re: Quicksort a string array (Case insensitive or standard)
« Reply #17 on: September 27, 2020, 08:07:13 pm »
By algorithm ? ...

No, in terms of implementation efficiency.


440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: Quicksort a string array (Case insensitive or standard)
« Reply #18 on: September 27, 2020, 09:57:06 pm »
There is another funny question. How many Pascal libraries do you know that are faster than the corresponding C library?
What are the applicable constraints to that question ?... given the _same_ algorithm, it's more likely that the C implementation will be faster simply because C compilers tend to optimize better than Pascal compilers. That's only because there is more effort put into C than in Pascal.  A Pascal compiler can be as good at optimizing as a C compiler but, code optimization does not seem to be the focus of Pascal compiler writers.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14198
  • Probably until I exterminate Putin.
Re: Quicksort a string array (Case insensitive or standard)
« Reply #19 on: September 28, 2020, 07:45:25 am »
In the case of FPC vs C it is also a matter of platform: x86_64 and i386 have more optimizations than other platforms.
Another note is that C often has more aggresive default settimgs, whereas FPC is conservative by default.
So you must also try and test with the same platform and CPU/FPU instruction sets. This can make a big difference here, e.g like copy operations using SSEx instead of on the CPU. The former is what C often selects, whereas FPC selects the CPU by default but CAN use SSEx)
Specialize a type, not a var.

 

TinyPortal © 2005-2018