Some PyFile benchmarks, mostly to show off the PyFile nio

Tests done on FreeBSD 6.2-RELEASE, Java 1.5.0_13 in server mode and Python 2.5.1

(If anyone's worried about FreeBSD Java, the times are in line with OS X's Java 1.5)

Preparations: 100

Test iterations (average taken of): 5

Notes:

* This page is made for a larger browser window so that the small and big graphs lie on the same row

* jython's file iter is roughly the same code as its readline, whereas CPython's readline is not as optimized as its iter. So the fact that our readline speed is very close to CPython's isn't totally fair, CPython's iter still beats us

* The few anomalies in the smaller benchmarks are probably due to JIT kicking in. Ideally we would run more preparations and iterations

* why is read slower than iter? profiling showed a lot of time being spent in allocating read's ByteBuffer, whereas iter uses a pre-allocated, smaller ByteBuffer. This still surprises me a bit, though. A PyString backed by bytes would help this particular benchmark a lot

* i don't have text mode benchmarks because they're only applicable to windows. their read times would be a little slower than 'U' mode. write times would probably lag behind CPython's

Reading:

   1     def test_read(self, fp):
   2         fp.read()
   3     test_read = bench(test_read)

[http://underboss.org/~pjenvey/jython/pyfile-nio/small/test_read.jpg] [http://underboss.org/~pjenvey/jython/pyfile-nio/big/test_read.jpg]

   1     def test_iter(self, fp):
   2         for line in fp:
   3             pass

[http://underboss.org/~pjenvey/jython/pyfile-nio/small/test_iter.jpg] [http://underboss.org/~pjenvey/jython/pyfile-nio/big/test_iter.jpg]

   1     def test_readline(self, fp):
   2         while fp.readline():
   3             pass

[http://underboss.org/~pjenvey/jython/pyfile-nio/small/test_readline.jpg] [http://underboss.org/~pjenvey/jython/pyfile-nio/big/test_readline.jpg]

   1     def test_readline_with_tell(self, fp):
   2         while fp.readline():
   3             fp.tell()

[http://underboss.org/~pjenvey/jython/pyfile-nio/small/test_readline_with_tell.jpg] [http://underboss.org/~pjenvey/jython/pyfile-nio/big/test_readline_with_tell.jpg]

   1     def test_readlines(self, fp):
   2         fp.readlines()

[http://underboss.org/~pjenvey/jython/pyfile-nio/small/test_readlines.jpg] [http://underboss.org/~pjenvey/jython/pyfile-nio/big/test_readlines.jpg]

Writing:

   1 MSG = ('abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz123456789'
   2        '0abcdefgh\r\n')

   1     def test_write(self, fp, lines):
   2         write = fp.write
   3         for i in range(lines):
   4             write(MSG)

[http://underboss.org/~pjenvey/jython/pyfile-nio/small/test_write.jpg] [http://underboss.org/~pjenvey/jython/pyfile-nio/big/test_write.jpg]

   1     def test_writelines(self, fp, lines):
   2         lines = [MSG for i in range(lines)]
   3         fp.writelines(lines)

[http://underboss.org/~pjenvey/jython/pyfile-nio/small/test_writelines.jpg] [http://underboss.org/~pjenvey/jython/pyfile-nio/big/test_writelines.jpg]