3-manifolds / Spherogram

Spherogram is a Python module for dealing with the kind of planar diagrams that arise in 3-dimensional topology, such as link and Heegaard diagrams. It a component of the larger SnapPy project.
https://snappy.math.uic.edu/spherogram.html
19 stars 8 forks source link

various small changes, some about len #38

Closed fchapoton closed 1 year ago

fchapoton commented 2 years ago
fchapoton commented 1 year ago

I have put back the tests using len (except the one in the while loop). Note that using not my_list is more pythonic and slightly more efficient.

fchapoton commented 1 year ago

Some timings

sage: A=[]
sage: B=list(range(1000))
sage: %timeit not A
19.7 ns ± 1.45 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
sage: %timeit not B
18.7 ns ± 0.0174 ns per loop (mean ± std. dev. of 7 runs, 100,000,000 loops each)
sage: %timeit len(A) == 0
160 ns ± 0.126 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
sage: %timeit len(B) == 0
211 ns ± 0.47 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)