Skip to content

Why did I find that it was not faster than javaio after testing? #660

@guangmomo

Description

@guangmomo

okio code

        Source source = null;
        BufferedSource bufferedSource = null;
        source = Okio.source(new File("zip1/SynalyzeItProTA_1.23.2.zip"));
        bufferedSource = Okio.buffer(source);
        Sink sink = null;
        BufferedSink bufferedSink = null;
        sink = Okio.sink(new File("zip2/1.zip"));
        bufferedSink = Okio.buffer(sink);
        int bufferSize = 8192; // 8kb
        long begin = System.currentTimeMillis();
        while (!bufferedSource.exhausted()) {
            bufferedSource.read(
                    bufferedSink.buffer(),
                    bufferSize
            );
            bufferedSink.emit();
        }
        System.out.println("timeIs:" + (System.currentTimeMillis() - begin)); 
        source.close();
        sink.close();

javaio code

        FileInputStream in = new FileInputStream("zip1/SynalyzeItProTA_1.23.2.zip");
        BufferedInputStream inBuffer = new BufferedInputStream(in);
        FileOutputStream out = new FileOutputStream("zip2/1.zip");
        BufferedOutputStream outBuffer = new BufferedOutputStream(out);
        int len = 0;
        byte[] bs = new byte[8192];
        long begin = System.currentTimeMillis();
        while ((len = inBuffer.read(bs)) != -1) {
            outBuffer.write(bs, 0, len);
        }
        System.out.println("timeIs" + (System.currentTimeMillis() - begin)); 
        inBuffer.close();
        in.close();
        outBuffer.close();
        out.close();

okio time is : 124ms
javaio time is: 77ms

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