Features of the mql5 language, subtleties and tricks - page 273
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
The fastest replacement for the built-in TimeToStruct() function,
I recommend using this function:
About 4-5 times faster (for the version without cache).
Added it here.
Indeed, your version is the fastest. Congratulations!
High-performance (vs built-in) time functions collected from various pages on this thread (not to get lost):
I am planning to publish it on the codebase, maybe after adding some other useful functions.
Added it here.
Indeed, your version is the fastest. Congratulations!
It the fastest I could get.
Another very fast option is using the computational calendar (fictitious calendar that starts on 1 March) and avoids the problem of dealing with leap years.
It is a new algorithm and very fast. See it here https://www.youtube.com/watch?v=0s9F4QWAl-E&t=1790s
Source: https://searchfox.org/mozilla-central/source/js/src/jsdate.cpp#263
https://github.com/torvalds/linux/blob/276010551664f73b6f1616dde471d6f0d63a73ba/kernel/time/timeconv.c#L77
High-performance (compared to inbuilt) time functions, collected from different pages of this thread (so they don't get lost):
I plan to publish it to the codebase, perhaps after adding some other useful features.
This is the fastest option I could find.
Another very fast option is to use a computational calendar (a dummy calendar starting on 1 March), which avoids the leap year problem.
This is a new algorithm and very fast. You can see it here https://www.youtube.com/watch?v=0s9F4QWAl-E&t=1790s.
Source: https: //searchfox.org/mozilla-central/source/js/src/jsdate.cpp#263
https://github.com/torvalds/linux/blob/276010551664f73b6f1616dde471d6f0d63a73ba/kernel/time/timeconv.c#L77
Real live test :
TimeToStruct 2024.11.26 17:03:55.501 Core 02 EURUSD,H1: 8667407 ticks, 37169 bars generated. Environment synchronized in 0:00:00.092. Test passed in 0:01:43.931.
TimeToStruct2100Old 2024.11.26 17:10:52.902 Core 02 EURUSD,H1: 8667407 ticks, 37169 bars generated. Environment synchronized in 0:00:00.081. Test passed in 0:01:41.173.
TimeToCalendar 2024.11.26 17:25:37.672 Core 02 EURUSD,H1: 8667407 ticks, 37169 bars generated. Environment synchronized in 0:00:00.088. Test passed in 0:01:40.153.
TimeToStructFast 2024.11.26 17:31:59.339 Core 02 EURUSD,H1: 8667407 ticks, 37169 bars generated. Environment synchronized in 0:00:00.091. Test passed in 0:01:41.471.
TimeToStruct2100Last 2024.11.26 17:37:43.948 Core 02 EURUSD,H1: 8667407 ticks, 37169 bars generated. Environment synchronized in 0:00:00.084. Test passed in 0:01:40.996.
TimeToStruct2100Cache 2024.11.26 17:42:40.774 Core 02 EURUSD,H1: 8667407 ticks, 37169 bars generated. Environment synchronized in 0:00:00.091. Test passed in 0:01:40.585.
It's hot start test with all data in memory.
Total number of call of the function :
2024.11.26 17:48:38.190 Core 02 2024.09.29 23:59:59 TTS Call = 191969676.
Forum on trading, automated trading systems and testing trading strategies
Features of mql5 language, subtleties and techniques of work
amrali, 2024.11.26 15:58
The fastest replacement for the built-in TimeToStruct() function,
I recommend using this function:
It's noticeably (AVX) faster that way.
Real live test :
TimeToStruct 2024.11.26 17:03:55.501 Core 02 EURUSD,H1: 8667407 ticks, 37169 bars generated. Environment synchronized in 0:00:00.092. Test passed in 0:01:43.931.
TimeToStruct2100Old 2024.11.26 17:10:52.902 Core 02 EURUSD,H1: 8667407 ticks, 37169 bars generated. Environment synchronized in 0:00:00.081. Test passed in 0:01:41.173.
TimeToCalendar 2024.11.26 17:25:37.672 Core 02 EURUSD,H1: 8667407 ticks, 37169 bars generated. Environment synchronized in 0:00:00.088. Test passed in 0:01:40.153.
TimeToStructFast 2024.11.26 17:31:59.339 Core 02 EURUSD,H1: 8667407 ticks, 37169 bars generated. Environment synchronized in 0:00:00.091. Test passed in 0:01:41.471.
TimeToStruct2100Last 2024.11.26 17:37:43.948 Core 02 EURUSD,H1: 8667407 ticks, 37169 bars generated. Environment synchronized in 0:00:00.084. Test passed in 0:01:40.996.
TimeToStruct2100Cache 2024.11.26 17:42:40.774 Core 02 EURUSD,H1: 8667407 ticks, 37169 bars generated. Environment synchronized in 0:00:00.091. Test passed in 0:01:40.585.
It's hot start test with all data in memory.
Total number of call of the function :
2024.11.26 17:48:38.190 Core 02 2024.09.29 23:59:59 TTS Call = 191969676.
Thanks Alain for your test. The replacement for built-in TimeToStruct() is only 4-5 times faster as I reported before.
However, the replacements for TimeYear(), TimeDayOfWeek() is at least 10-20 times faster than using MQL's TimeToStruct()
This code executes slow while using wrappers of built-in StructToTime.
Using the optimized functions really helps here.
Another thing: decompressing (TimeToStruct) is always faster than compressing (StructToTime). Built-in StructToTime is really slow than TimeToStruct().
If your code is creating a lot of 'datetime' variables from time components, you will find CreateDateTime() is much faster than MQL's StructToTime().
I faced the problem of slow StructToTime() while constructing datetime variables for Daylight switch times in TimeZoneInfo library. Replacing it for this custom CreateDateTime() made a nice improvement in speeds.
It's noticeably (AVX) faster that way.
Unfortunately not faster than current implementation:
Unfortunately, no faster than the current implementation:
I have a different picture. Share the source of the script, please.