#15912: pretty print too slow with long lists
-------------------------+-------------------------------------------------
   Reporter:  rws        |            Owner:
       Type:  defect     |           Status:  new
   Priority:  major      |        Milestone:  sage-6.2
  Component:             |         Keywords:  pretty, output, lists,
  performance            |  factorial
  Merged in:             |          Authors:
  Reviewers:             |  Report Upstream:  N/A
Work issues:             |           Branch:
     Commit:             |     Dependencies:
   Stopgaps:             |
-------------------------+-------------------------------------------------
 Assume a student who, in a mood of serendipity, plays with Sage. While
 both pari and Sage use on the order of 10ms to compute the divisors of
 20!:

 {{{
 ? divisors(20!)

 sage: divisors(Integer(20).factorial())
 }}}

 the actual time for screen output is much different, where I would
 estimate pari with less than 100ms but Sage with about 2.5 sec in a
 terminal on a 3GHz machine. The list has 41040 entries. Sage seems to
 buffer the stuff somewhere before actual output, and this appears to take
 a lot of CPU.

 You can imagine what happens with 30! where both Sage and pari need 1-2
 sec for computation. I had to interrupt Sage after a minute to see this
 backtrace:

 {{{
 /home/ralf/sage/local/lib/python2.7/site-
 packages/IPython/core/displayhook.pyc in __call__(self, result)
     236             self.start_displayhook()
     237             self.write_output_prompt()
 --> 238             format_dict = self.compute_format_data(result)
     239             self.write_format_data(format_dict)
     240             self.update_user_ns(result)

 /home/ralf/sage/local/lib/python2.7/site-
 packages/IPython/core/displayhook.pyc in compute_format_data(self, result)
     148             MIME type representation of the object.
     149         """
 --> 150         return self.shell.display_formatter.format(result)
     151
     152     def write_format_data(self, format_dict):

 /home/ralf/sage/local/lib/python2.7/site-
 packages/IPython/core/formatters.pyc in format(self, obj, include,
 exclude)
     124                     continue
     125             try:
 --> 126                 data = formatter(obj)
     127             except:
     128                 # FIXME: log the exception

 /home/ralf/sage/local/lib/python2.7/site-
 packages/sage/misc/displayhook.pyc in __call__(self, obj)
     508         s = self.try_format_obj(obj)
     509         if s is None:
 --> 510             s = super(SagePlainTextFormatter, self).__call__(obj)
     511         return s
     512

 /home/ralf/sage/local/lib/python2.7/site-
 packages/IPython/core/formatters.pyc in __call__(self, obj)
     445                 type_pprinters=self.type_printers,
     446                 deferred_pprinters=self.deferred_printers)
 --> 447             printer.pretty(obj)
     448             printer.flush()
     449             return stream.getvalue()

 /home/ralf/sage/local/lib/python2.7/site-packages/IPython/lib/pretty.pyc
 in pretty(self, obj)
     343                 if cls in self.type_pprinters:
     344                     # printer registered in self.type_pprinters
 --> 345                     return self.type_pprinters[cls](obj, self,
 cycle)
     346                 else:
     347                     # deferred printer

 /home/ralf/sage/local/lib/python2.7/site-packages/IPython/lib/pretty.pyc
 in inner(obj, p, cycle)
     527                 p.text(',')
     528                 p.breakable()
 --> 529             p.pretty(x)
     530         if len(obj) == 1 and type(obj) is tuple:
     531             # Special case for 1-item tuples.

 /home/ralf/sage/local/lib/python2.7/site-packages/IPython/lib/pretty.pyc
 in pretty(self, obj)
     346                 else:
     347                     # deferred printer
 --> 348                     printer = self._in_deferred_types(cls)
     349                     if printer is not None:
     350                         return printer(obj, self, cycle)

 /home/ralf/sage/local/lib/python2.7/site-packages/IPython/lib/pretty.pyc
 in _in_deferred_types(self, cls)
     372         """
     373         mod = getattr(cls, '__module__', None)
 --> 374         name = getattr(cls, '__name__', None)
     375         key = (mod, name)
     376         printer = None

 /home/ralf/sage/local/lib/python2.7/site-packages/sage/ext/c_lib.so in
 sage.ext.c_lib.sage_python_check_interrupt (sage/ext/c_lib.c:1634)()

 /home/ralf/sage/local/lib/python2.7/site-packages/sage/ext/c_lib.so in
 sage.ext.c_lib.sig_raise_exception (sage/ext/c_lib.c:835)()

 KeyboardInterrupt:
 }}}
 The student was not exactly encouraged to continue using Sage.

--
Ticket URL: <http://trac.sagemath.org/ticket/15912>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to