From 6e38fc5e741f9303c3af970f0ee58a377c6cfdc7 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Fri, 24 Jan 2020 21:58:05 +0000 Subject: [PATCH] examples/wrapping_generators --- examples/wrapping_generators.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 examples/wrapping_generators.py diff --git a/examples/wrapping_generators.py b/examples/wrapping_generators.py new file mode 100644 index 00000000..0ec06895 --- /dev/null +++ b/examples/wrapping_generators.py @@ -0,0 +1,14 @@ +from tqdm.contrib import tenumerate, tzip, tmap +import numpy as np + +for _ in tenumerate(range(int(1e6)), desc="builtin enumerate"): + pass + +for _ in tenumerate(np.random.random((999, 999)), desc="numpy.ndenumerate"): + pass + +for _ in tzip(np.arange(1e6), np.arange(1e6) + 1, desc="builtin zip"): + pass + +mapped = tmap(lambda x: x + 1, np.arange(1e6), desc="builtin map") +assert (np.arange(1e6) + 1 == list(mapped)).all()