PineCoders

Script Stopwatch - PineCoders FAQ

PineCoders Mod Обновлено   
█ WARNING


The publication of our LibraryStopwatch has deprecated this publication.



█ ORIGINAL DESCRIPTION


This script calculates the run time of a Pine script. While its numbers are not very precise and it doesn’t work on all scripts, it will help developers calculate run times more precisely than by hand, and so provides Pine coders with an additional profiling tool to help them optimize their code.

How to use the code
• Place the code included between the up/down arrows after your script’s input() calls.
• Comment out the display modes you don’t want to use.
• Save your script, wait and look at the results.
• Results show in different colors, depending on the average time per bar:
- green for < 5 ms
- dark red for < 50 ms
- bright red for > 50 ms (the maximum allowed is 200).

How the code works
The code in this script starts by saving the value of the timenow variable on the first bar. While the time variable returns the time at the beginning of the bar, timenow returns the current time. The code then follows the progression of timenow during the script’s execution. The variable only updates every second, so in between updates the script makes an estimate of the total time elapsed by adding the last average time per bar calculated to each bar that passes until timenow increases by another 1000 because one more second has elapsed since its last update. At that point a new, current average time per bar is calculated and the cycle repeats.

The code only calculates elapsed time for the initial run. Once the realtime bar is hit, timing stops so that time spent in the realtime bar does not affect the numbers once they have been calculated on the script’s initial pass over the dataset.

Notes
• If results show zero elapsed time, it’s most probably because your script executes in less than one second, which is very good. In that case timenow hasn’t changed, so no timing can be calculated.
• The code is quirky and doesn’t work on all scripts.
• It doesn’t properly time execution of security() calls.
• The average time per bar will sometimes vary quite a bit with changes in chart resolution.



Look first. Then leap.

Информация о релизе:
Updated comments.
Информация о релизе:
More efficient label code.
Информация о релизе:
Added a plot at the end to force timing of the script.

Tools and ideas for all Pine coders: www.pinecoders.com
Our Pine FAQ & Code: www.pinecoders.com/faq_and_code/
Pine news broadcasts: t.me/PineCodersSquawkBox or twitter.com/PineCoders
Скрипт с открытым кодом

В истинном духе TradingView автор этого скрипта опубликовал его с открытым исходным кодом, чтобы трейдеры могли понять, как он работает, и проверить на практике. Вы можете воспользоваться им бесплатно, но повторное использование этого кода в публикации регулируется Правилами поведения. Вы можете добавить этот скрипт в избранное и использовать его на графике.

Отказ от ответственности

Все виды контента, которые вы можете увидеть на TradingView, не являются финансовыми, инвестиционными, торговыми или любыми другими рекомендациями. Мы не предоставляем советы по покупке и продаже активов. Подробнее — в Условиях использования TradingView.

Хотите использовать этот скрипт на графике?