File I/O Metrics

Garrett Dangerfield <[email protected]> Fri, 21 Oct 2022 11:43:34 -0700
Newsgroups gmane.editors.j.devel
Message-ID <CAH3WWf_sE6z6=6cPVPJVTgmt6AvmS0Y-nCB5vnNjwkEWVE8WbQ@mail.gmail.com>
--0000000000006b8dba05eb8fd207
Content-Type: text/plain; charset="UTF-8"

I don't want to cause a firestore here but I was doing some simple
benchmarks on file i/o between Java, ABCL, and SBCL and I'm a bit shocked,
honestly.

Reading a 2.5M file in 16M chunks in (using iso-8859-1):
- abcl takes a tad over 1 second
- sbcl takes 0.04 seconds

Reading a 5.8G file in 16M chunks in (using iso-8859-1 for Lisp, for Java
it's just bytes):
- abcl takes...too long, I gave up
- sbcl takes between 20 and 21 seconds
- Java takes 1.5 seconds

These are all run on the same computer using the same files, etc.

What's up with this?  Thoughts?  I'd heard that SBCL should be as fast as C
under at least some circumstances.  I'd wager that C is at least as fast as
Java (probably faster).

Thanks,
Garrett Dangerfield. (he/him/his)

P.S. Don't get me wrong, I *LOVE* Lisp, I'm trying to get away from Java as
fast as I can (the syntax is killing me slowly).  I've used ABCL in
projects before (it was wonderful, Java doesn't handle XML well).

Lisp code:
  (with-open-file (stream "/media/danger/OS/temp/jars.txt" :external-format
:iso-8859-1) ; great_expectations.iso
 (let ((size (file-length stream))
(buffer-size (* 16 1024 1024)) ; 16M
)
   (time
    (loop with buffer = (make-array buffer-size :element-type 'character)
  for n-characters = (read-sequence buffer stream)
  while (< 0 n-characters)))
   )))

Java code:
private static final int BUFFER_SIZE = 16 * 1024 * 1024;
try (InputStream in = new
FileInputStream("/media/danger/OS/temp/great_expectations.iso"); ) {
byte[] buff = new byte[BUFFER_SIZE];
int chunkLen = -1;
long start = System.currentTimeMillis();
while ((chunkLen = in.read(buff)) != -1) {
System.out.println("chunkLen = " + chunkLen);
}
double duration = System.currentTimeMillis() - start;
duration /= 1000;
System.out.println(String.format("it took %,2f secs", duration));
} catch (Exception e) {
e.printStackTrace(System.out);
} finally {
System.out.println("Done.");
}

--0000000000006b8dba05eb8fd207
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I don&#39;t want to cause a firestore here but I was =
doing some simple benchmarks on file i/o between Java, ABCL, and SBCL and I=
&#39;m a bit shocked, honestly.</div><div><br></div><div>Reading a 2.5M fil=
e in 16M chunks in (using iso-8859-1):</div><div>- abcl takes a tad over 1 =
second</div><div>- sbcl takes 0.04 seconds</div><div><br></div><div>Reading=
 a 5.8G file in 16M chunks in (using iso-8859-1 for Lisp, for Java it&#39;s=
 just bytes):</div><div>- abcl takes...too long, I gave up</div><div>- sbcl=
 takes between 20 and 21 seconds</div><div>- Java takes 1.5 seconds</div><d=
iv><br></div><div>These are all run on the same computer using the same fil=
es, etc.<br></div><div><br></div><div>What&#39;s up with this?=C2=A0 Though=
ts?=C2=A0 I&#39;d heard that SBCL should be as fast as C under at least som=
e circumstances.=C2=A0 I&#39;d wager that C is at least as fast as Java (pr=
obably faster).<br></div><div><br></div><div>Thanks,</div><div>Garrett Dang=
erfield. (he/him/his)<br></div><div><br></div><div>P.S. Don&#39;t get me wr=
ong, I *LOVE* Lisp, I&#39;m trying to get away from Java as fast as I can (=
the syntax is killing me slowly).=C2=A0 I&#39;ve used ABCL in projects befo=
re (it was wonderful, Java doesn&#39;t handle XML well).<br></div><div><br>=
</div><div>Lisp code:</div><div>=C2=A0 (with-open-file (stream &quot;/media=
/danger/OS/temp/jars.txt&quot; :external-format :iso-8859-1) ; great_expect=
ations.iso<br>		 =C2=A0(let ((size (file-length stream))<br>			(buffer-size=
 (* 16 1024 1024)) ; 16M<br>			)<br>=C2=A0=C2=A0 (time<br>		 =C2=A0 =C2=A0 =
(loop with buffer =3D (make-array buffer-size :element-type &#39;character)=
<br>			 =C2=A0 for n-characters =3D (read-sequence buffer stream)<br>			 =
=C2=A0 while (&lt; 0 n-characters)))<br>=C2=A0=C2=A0 )))<br></div><div><br>=
</div><div>Java code:</div><div>			private static final int BUFFER_SIZE =3D=
 16 * 1024 * 1024;<br>try (InputStream in =3D new FileInputStream(&quot;/me=
dia/danger/OS/temp/great_expectations.iso&quot;); ) {<br>			byte[] buff =3D=
 new byte[BUFFER_SIZE];<br>			int chunkLen =3D -1;<br>			long start =3D Sys=
tem.currentTimeMillis();<br>			while ((chunkLen =3D in.read(buff)) !=3D -1)=
 {<br>				System.out.println(&quot;chunkLen =3D &quot; + chunkLen);<br>			}=
<br>			double duration =3D System.currentTimeMillis() - start;<br>			durati=
on /=3D 1000;<br>			System.out.println(String.format(&quot;it took %,2f sec=
s&quot;, duration));<br>		} catch (Exception e) {<br>			e.printStackTrace(S=
ystem.out);<br>		} finally {<br>			System.out.println(&quot;Done.&quot;);<b=
r>		}</div><div><br></div></div>

--0000000000006b8dba05eb8fd207--