Skip to content

Instantly share code, notes, and snippets.

@nishio
Created August 27, 2010 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nishio/553321 to your computer and use it in GitHub Desktop.
Save nishio/553321 to your computer and use it in GitHub Desktop.
diff -r 47352a8373fe prettyprint/prettyprint.py
--- a/prettyprint/prettyprint.py Fri Aug 27 21:25:45 2010 +0900
+++ b/prettyprint/prettyprint.py Fri Aug 27 22:16:07 2010 +0900
@@ -192,15 +192,15 @@
return Line_(i, be(width, i, tail))
if isinstance(y, Union):
return better(width, already,
- be(width, already, [(i, y.x)] + tail),
- be(width, already, [(i, y.y)] + tail))
+ lambda:be(width, already, [(i, y.x)] + tail),
+ lambda:be(width, already, [(i, y.y)] + tail))
raise NotImplementedError(x)
def better(width, already, x, y):
if fits(width - already, x):
- return x
- return y
+ return x()
+ return y()
def fits(width, x):
if width < 0: return False
@@ -280,5 +280,10 @@
import doctest
doctest.testmod()
+def _performance():
+ print pretty(10, reduce(can_break, (Text(str(word)) for word in range(18))))
+
if __name__ == "__main__":
_test()
+ import cProfile
+ cProfile.run("_performance()")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment