Is there any difference between using log.info() and print besides the latter having the prefix "PRINT" in the output? Are both methods throttled? Any performance difference?
Is there any difference between using log.info() and print besides the latter having the prefix "PRINT" in the output? Are both methods throttled? Any performance difference?
Hi Alex,
Using log.info() gives a bit more information such as the function/line where the log statement was made. Both are throttled with the same limits. There's no significant performance difference between the two, especially considering the limitation on number of lines that can be printed/logged. The logger also offers different levels such as .warn() or .error() which can be convenient in some cases. In the end, it's a matter of preference!
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.
When I saw Alex's message I thought, ah great, a chance for me to try this Timing Code, and I expected them to be about the same, or print to be slightly faster. I only ran this once however print was 32x slower on average. Hard to believe.
Anyway, here's some timing code attached for anyone to try.
Edit: Aha, reversing the order of them, with log.info() prior to print, log.info() is slower.
So Jamie is right I'll bet, virtually no difference, something about the backtester I suppose.
Edit2: Doing print and log.info() first in handle_data without timing them, then timing them separately after that, they're identical.
Seems the first one encountered takes extra time in each bar.
2016-01-07 timing:79 INFO Timings by highs descending:
2016-01-07 timing:81 INFO avg 0.013743 lo 0.000354 hi 1.023956 print
2016-01-07 timing:81 INFO avg 0.000425 lo 0.000329 hi 0.008549 loginf