I found MessagePacker#packString is slow when outputting to FileOutputStream.
private static void packStrings(String label, String s, int count, OutputStream outputStream)
throws IOException
{
System.out.println(label);
MessagePacker messagePacker = MessagePack.newDefaultPacker(outputStream);
long start = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
messagePacker.packString(s);
}
messagePacker.close();
System.out.println(System.currentTimeMillis() - start);
}
public static void main(String[] args)
throws IOException
{
int count = 5000000;
String s = "0123456789";
packStrings("ByteArrayOutputStream", s, count, new ByteArrayOutputStream());
packStrings("FileOutputStream", s, count, new FileOutputStream("/tmp/x.bin"));
packStrings("FileOutputStream + BufferedOutputStream", s, count, new BufferedOutputStream(new FileOutputStream("/tmp/x.bin")));
}
ByteArrayOutputStream
1056
FileOutputStream
19084
FileOutputStream + BufferedOutputStream
854
I found MessagePacker#packString is slow when outputting to FileOutputStream.