Skip to content

MessagePacker#packString is slow when outputting to FileOutputStream #292

Description

@komamitsu

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions