I've written some code that resembles FileTimeToSystemTime from Win32.
In that code I did needed to get the month and the day from a FILETIME (100ns-intervals) offset within a year. I did this with a binary search
on a table, but although the code isn't performance-critical I asked
myself if a linear search would be faster because there would be less
branch misspredictions than with the binary search - there are only a
few elements so that the linear search might be faster:
Am 06.01.22 um 09:21 schrieb Bonita Montero:
I've written some code that resembles FileTimeToSystemTime from Win32.
In that code I did needed to get the month and the day from a FILETIME
(100ns-intervals) offset within a year. I did this with a binary search
on a table, but although the code isn't performance-critical I asked
myself if a linear search would be faster because there would be less
branch misspredictions than with the binary search - there are only a
few elements so that the linear search might be faster:
This is typical.
1. The branch prediction you already mentioned.
2. Random memory access is slower than linear memory access.
Details highly depend on cache line size and object size, of course. As
long as the entire fable fits into a single cache line there is no difference.
The code with the linear search is about 17% faster !
For one, you binary search version does not attamtp to take advantage
of a possible "lucky hit". ...
Am 07.01.2022 um 21:28 schrieb Andrey Tarasevich:
For one, you binary search version does not attamtp to take advantage
of a possible "lucky hit". ...
Show me the code where a "lucky hit" is sufficient.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 112 |
Nodes: | 8 (1 / 7) |
Uptime: | 26:12:39 |
Calls: | 2,468 |
Files: | 8,627 |
Messages: | 1,892,288 |