to find "first Monday of the previous month" , "the beginning of the current quarter" etc.
And just to decompose the current date into day-month-year (to know) it may be necessary once a day and this moment is not critical. Nobody calls TimeToStruct on every tick :-)
I had to call dt.day_of_week 500k times in a loop that scans history. It happens.
I flew over it and it seems all operations are in the most efficient way structured. I dont think there is more improvement possible, but I said that before already. - Obviously, I was wrong.
Meaning, if there is a better implementation than the stock one, it would make sense for MQ to replace the stock one with a better one.
Not necessarily. MQ is facing a totally different challenge. They need to make sure to not break old code, and they need to put maintenance towards any code they have in their products.
So if MQ uses some windows API function to do the job, they reduced their code footprint and maintenance labor. MQ is most probably focused on reliable and functional. They do not focus a week on one function to make it the most efficient code possible.
When you run a software as a product, you are focused on other aspects. Think of it like a car manufacturer. They dont sell you F1 cars. But you can tune it later as you like.
And this code is no different. Its a tuning equipment for your program.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
And inverse ?
I mean that TimeToStruct is usually paired with the inverse StructToTime function.
to find "first Monday of the previous month" , "the beginning of the current quarter" etc.
And just to decompose the current date into day-month-year (to know) it may be necessary once a day and this moment is not critical. Nobody calls TimeToStruct on every tick :-)
For the fastest replacement to the built-in TimeToStruct() function,
I suggest using this function :
The speed-up factor is approx. 4-5x (for the version without cache).
After applying optimizations from this paper "Euclidean Affine Functions and Applications to Calendar Algorithms":
Results:
/* Compiler Version: 4620, X64 Regular 13th Gen Intel Core i3-1305U, AVX2 + FMA3 1970.01.01 00:05:17 - 2099.11.29 23:56:35, random datetimes[] 5.20 ns, checksum = 151984615301017 // TimeToStruct2100 5.18 ns, checksum = 151984615301017 // TimeToStructFast 4.52 ns, checksum = 151984615301017 // TimeToStructFast2 4.87 ns, checksum = 151984615301017 // TimeToCalendar 5.62 ns, checksum = 151984615301017 // TimeToJulian 23.08 ns, checksum = 151984615301017 /// MQL's TimeToStruct() */After applying optimisations from the article "Euclidean affine functions and their application to calendar algorithms ":
Thanks, very interesting solution.
You can use smaller numbers in the expression.
After applying optimizations from this paper "Euclidean Affine Functions and Applications to Calendar Algorithms":
Results:
Supposedly MQ should now replace the implementation of the inbuilt f-function with this one?
It should be checked for dates after 2100. The year is 365.2425 days long, not 365.25.
Supposedly, MQs should now replace the implementation of the inbuilt f-function with this one?
Supposedly, MQs should now replace the implementation of the inbuilt f-function with this one?
Also, why. Just replace it yourself. Look at the amralis library, it shows how to do it.
Meaning, if there is a better implementation than the stock one, it would make sense for MQ to replace the stock one with a better one.
Meaning, if there is a better implementation than the stock one, it would make sense for MQ to replace the stock one with a better one.