Recent

Author Topic: Benchmark test in nanoseconds  (Read 4635 times)

backprop

  • Full Member
  • ***
  • Posts: 202
Re: Benchmark test in nanoseconds
« Reply #45 on: March 04, 2026, 06:16:16 am »
@backprop

I think you have enough material to do your work.
If you don't have any other question about the topic I stop here.

Last suggestion: like @marcov suggest with his link, use the coreinfo (or better coreinfo64) utility of sysinternals to know if your system has TSC invariant.

And if you decide to use RDTSC (that is not a bad choice at all), construct something like TStopWatch with RDTSC to use in your applications, so you can adapt this to all platforms you use with only one design in you sources.

Thank you for your input, I appreciate it. I already have my own class made some 20 years ago which do such measurements with Delphi, as I mentioned and I copy and paste here some code from it. But main difference today is so many cores and hyper threads in CPU and advanced optimization at CPU level. Only what I needed actually is proper way to use RDTSC, basically on Linux and FPC/Lazarus. And as I use FPC/Lazarus just for fun and my personal use, I do not see much of the problems regarding porting code and using on other platforms nor I care much about Windows, especially Windows 11.

I missing few more things here... Since I'm more in C/C++ today, what I missing here is volatile declaration for variables. As well, I would like to turn off optimization just for the part of desired code. Hope both is possible...

creaothceann

  • Sr. Member
  • ****
  • Posts: 279
Re: Benchmark test in nanoseconds
« Reply #46 on: March 04, 2026, 07:08:20 am »
I would like to turn off optimization just for the part of desired code
Afaik should be possible with

Code: Pascal  [Select][+][-]
  1. {$push}  {$optimization NoLoopUnroll}
  2.  
  3. // some code
  4.  
  5. {$pop}

LeP

  • Full Member
  • ***
  • Posts: 207
Re: Benchmark test in nanoseconds
« Reply #47 on: March 04, 2026, 09:30:21 am »
I missing few more things here... Since I'm more in C/C++ today, what I missing here is volatile declaration for variables. As well, I would like to turn off optimization just for the part of desired code. Hope both is possible...
'volatile' has no meaning in Pascal (talk about Delphi, with FPC I don't know) but you can obtain the same with the ' [$O]' compiler conditional.
You can apply that a full procedure / function / method level (I mean you cannnot apply it to a single or a group lines of code).

EDIT: not really the same, you have to write more code since volatile is decalred a variable level on C and compiler condiitional on PAscal works on block of code. So you should apply compiler conditional everywhere you use a volatile variable.
« Last Edit: March 04, 2026, 09:39:16 am by LeP »

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1186
Re: Benchmark test in nanoseconds
« Reply #48 on: March 07, 2026, 03:27:08 pm »
@backprop

I think you have enough material to do your work.
If you don't have any other question about the topic I stop here.

Last suggestion: like @marcov suggest with his link, use the coreinfo (or better coreinfo64) utility of sysinternals to know if your system has TSC invariant.

And if you decide to use RDTSC (that is not a bad choice at all), construct something like TStopWatch with RDTSC to use in your applications, so you can adapt this to all platforms you use with only one design in you sources.
Thank you for your input, I appreciate it. I already have my own class made some 20 years ago which do such measurements with Delphi, as I mentioned and I copy and paste here some code from it. But main difference today is so many cores and hyper threads in CPU and advanced optimization at CPU level. Only what I needed actually is proper way to use RDTSC, basically on Linux and FPC/Lazarus. And as I use FPC/Lazarus just for fun and my personal use, I do not see much of the problems regarding porting code and using on other platforms nor I care much about Windows, especially Windows 11.

I missing few more things here... Since I'm more in C/C++ today, what I missing here is volatile declaration for variables. As well, I would like to turn off optimization just for the part of desired code. Hope both is possible...
Interesting.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12719
  • FPC developer.
Re: Benchmark test in nanoseconds
« Reply #49 on: March 07, 2026, 06:56:26 pm »
  volatile declaration for variables.

Volatile requires quite high level optimisations, specially for memory I/O. Since most OSes nowadays abstract you from the hardware, this is mostly for embedded with memory mapped I/O and interrupt routines.

FPC will need it at some point, but probably it will be some attribute rather than a language keyword.
« Last Edit: March 07, 2026, 07:09:15 pm by marcov »

PascalDragon

  • Hero Member
  • *****
  • Posts: 6356
  • Compiler Developer
Re: Benchmark test in nanoseconds
« Reply #50 on: March 07, 2026, 11:14:15 pm »
  volatile declaration for variables.

Volatile requires quite high level optimisations, specially for memory I/O. Since most OSes nowadays abstract you from the hardware, this is mostly for embedded with memory mapped I/O and interrupt routines.

FPC will need it at some point, but probably it will be some attribute rather than a language keyword.

Uhm... FPC already has an intrinsic for declaring a specific operation (read or store) as volatile.

 

TinyPortal © 2005-2018