Joel Uckelman on Mon, 3 Jan 2005 13:27:55 -0600 (CST)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[nimh-dev] formats and execution speed


[uckelman@scylla nimh]$ time scan +inbox
.
.
.
real    0m0.040s
user    0m0.012s
sys     0m0.020s

[uckelman@scylla bin]$ time PYTHONPATH=~/projects/nimh/trunk/lib ./nscan.py
 +inbox
.
.
.
real    0m0.672s
user    0m0.446s
sys     0m0.194s

Not good. My inbox contains only 153 messages. The time for scan is an
underestimate---it takes longer for the terminal to catch up than it does
for scan to exit---but the difference between the two is noticeable.

Here's what my test format looks like:

for msg_num in msg_list:
  msg = cur_folder.openmessage(msg_num)

  if msg.number == cur_msg: is_cur_char = '+'
  else: is_cur_char = ' '

  self.date =  None
  date = msg['Date']

  subject = self.flatten(msg['Subject'], 47)
  body = self.flatten(str(msg.get_payload()), 47 - len(subject))

  print ('%4i%s %02i/%02i %s  %s<<%s>>' % ( \
      msg.number, \
      is_cur_char, \
      self.mon(date), \
      self.mday(date), \
      self.friendly(msg['From'])[:17].ljust(17), \
      subject, \
      body \
  ))[:self.cols-1]

This is being exec'ed from Format.inst_loop(), which is called from scan.
(None of this has been comitted yet because it's very much in flux right
now.) Originally, I had the loop you see in the format code outside of the
exec, which meant that exec was being called once for each message. Putting
the loop inside the format cut out 152 calls to exec and reduced scan time
over my inbox by 0.3s.

Some things to consider:

1. The only programs for which execution time of formats matters are scan
and inc, since they're the only programs which instantiate a format more
than once.
2. I'd like this to execute about twice as fast as it does now.
3. 2 may not be possible without some really grotesque optimizations.
4. I think that the Python format above is uglier than the same written
in the mh-format language. (And it isn't quite equivalent, either. E.g.,
it doesn't display To instead of From for messages you sent.)

Thoughts?

BTW, have you guys died or something? I know Tom has been busy, what with
getting engaged and all, but what about you, Jon?

_______________________________________________
nimh-dev mailing list
nimh-dev@xxxxxxxxxxx
http://lists.ellipsis.cx/mailman/listinfo/nimh-dev