-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
print() is 68 times faster than ic() #36
Comments
Finding where #33 should make repeated calls faster. |
Sorry about the 100 times vs 1000 times. The elapsed time is actually correct, I just put in wrong code. |
Is IceCream is a debugging library and thus should not be performance-critical (eg used in a tight loop in production). As @alexmojaki mentioned, If you want to dive in to improve IceCream's performance, I'd ebulliently welcome and merge such PRs. But performance is not my focus with IceCream until it presents itself as a problem. As for tight loops and/or production, the forthcoming #33 (also a huge thanks to @alexmojaki there) will help. |
When I was interacting with UI elements and the UI will report some number in the command line. E.g. dragging a slider and then it computes something. The ic() will make the slider look unresponsive if you move the slider passes through many callback points quickly (like from 0 to 100). |
Aha. That would do it. Great example of an A threaded implementation would solve this. Do all Is this something you could tackle? |
No. I don't know threading in python yet. |
Try using the |
I see that snoop seems to be more intense in its number of features, providing more options than ic. Though ic is simple and easy to get started. |
Yes, Using |
@alexmojaki Yes. I tried experimenting with this code from time import time
from icecream import ic
from snoop import pp
def process(print_func, n_iter):
start = time()
for i in range(n_iter):
print_func(i)
stop = time()
elapsed = stop - start
return elapsed
n_iter = 10_000
e1 = process(lambda i: print("i:", i), n_iter)
e2 = process(ic, n_iter)
e3 = process(pp, n_iter)
print("print elapsed:", e1)
print("ic elapsed:", e2)
print("pp elapsed:", e3)
print(f"print() is {e2 / e1} times faster than ic()")
print(f"print() is {e3 / e1} times faster than pp()") And here is the result: print elapsed: 0.5972144603729248
ic elapsed: 43.248204708099365
pp elapsed: 3.786238431930542
print() is 72.41653974870843 times faster than ic()
print() is 6.339830468214487 times faster than pp() So yeah, pp is definitely faster than ic! I don't know why I would not use it. You need a more catchy naming of the library and that's it. Also it doesn't have the issue I mentioned here: #35 |
Thanks for pointing this out to me. IPython does some extra magic which makes it harder for |
I will close this issue for now as it seems like I can get around with slowness issue by using |
this sounds like an issue, perhaps, outside icecream. behind the scenes icecream just calls def stderrPrint(*args):
print(*args, file=sys.stderr) can you
and
ic.configureOutput(outputFunction=print) is the same character by character delay seen? |
Not niche issue. |
to be explicit, using this configuration ic.configureOutput(outputFunction=print) right? |
Try the following code to test speed of print() vs ic():
I found that print is 68 times faster!
How to make it faster? Why is it so slow? Is it because of the coloring?
The text was updated successfully, but these errors were encountered: