You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Ive come across this project recently...
https://github.com/PlummersSoftwareLLC/Primes
Accomodated by this video:
https://www.youtube.com/watch?v=tQtFdsEcK_s&list=PLF2KJ6Gy3cZ5Er-1eF9fN1Hgw_xkoD9V1
eval = (data[cnt] > 0x7F); left[left_ptr] = (data[cnt] * eval) + (left[left_ptr] * !(eval)); left_ptr += eval;
The result of the expression is assigned to variable 'eval', so it is OK.
But,
((test1) || ((test2) && (MyConditionFunc() == 1)) ) && MyTestFunc();
The compiler complains warning: "result of expression not used", because the value of the expression is not assigned to any variable. The expression will be evaluated but it is not a valid statement.
Look for statements vs expressions to understand the difference.
The boolean expression is evaluated according to the short-circuit evalution.
https://en.wikipedia.org/wiki/Short-circuit_evaluation
BTW: branchless code always executes faster than code with branching. It is a fact, but this is another topic.
Your code still has branching, to convert it to branchless use:
Edit:
The difference found in the benchmarks is due to different condtions for branching plus some compiler optimizations.
Not all branching is bad. In addition to compiler optimizations, modern CPUs have branch predictors. It is a harware optimization for if..else statements.
Please refer to this link for a nice explanation about branch prediction:
https://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-processing-an-unsorted-array
Keep in mind, by using this
you actually, turn off compiler optimizations and cpu branch predictors. Plus you sacrifice code readibility for performance. So, it is better to be reserved for performance-critical loops.
...
BTW: branchless code always executes faster than code with branching. It is a fact, but this is another topic.
Your code still has branching, to convert it to branchless use:
Edit:
The difference found in the benchmarks is due to different condtions for branching plus some compiler optimizations.
Your example code is the proof your statement is false actually.
2021.07.11 06:03:08.015 372818 (EURUSD,M1) BINARY SHIFT Loop time: 2.4 nanosec; total time: 40982 microsec. Left = 1606418432 Right = 532676545
Your example code is the proof your statement is false actually.
2021.07.11 06:03:08.015 372818 (EURUSD,M1) BINARY SHIFT Loop time: 2.4 nanosec; total time: 40982 microsec. Left = 1606418432 Right = 532676545
You know Alain, I tested it on laptop with core i3 and branchless code was faster. This proves that it greatly depends on L1, L2 cache, pipeline capacity among other compiler optimizations.
Interesting. Do you mind to post the results ?
My setup :
2021.07.09 15:36:53.702 Terminal Windows 10 build 19042, Intel Core i7-9750H @ 2.60GHz, 12 / 15 Gb memory, 62 / 279 Gb disk, IE 11, UAC, GMT-5
Interesting. Do you mind to post the results ?
My setup :
2021.07.09 15:36:53.702 Terminal Windows 10 build 19042, Intel Core i7-9750H @ 2.60GHz, 12 / 15 Gb memory, 62 / 279 Gb disk, IE 11, UAC, GMT-5
Hi Alain, I have checked your code. With the ternary operator, you are actually comparing apples to oranges. Your code increment the left and right pointers unconditionally, this is reflected on your shorter execution time, unlike the original code, which increment the pointers based on the condition.
Here is my results afer I made some corrections.