Le 12/03/2012 00:02, Benedikt Ritter a écrit :

I've started to dig my way through the source. I've not done too much
performance measuring in my career yet. I would use VisualVM for
profiling, if you don't know anything better.

Usually I work with JProfiler, it identifies the "hotspots" pretty well, but I'm not sure if it will produce relevant results on the complex methods of CSVLexer.


And how about some performance junit tests? They may not be as
accurate as a profiler, but they can give you a feeling, whether you
are on the right way.

I wrote a quick test locally, but that's not clean enough to be committed. It looks like this:


public class PerformanceTest extends TestCase {

    private int max = 10;

    private BufferedReader getReader() throws IOException {
        return new BufferedReader(new FileReader("worldcitiespop.txt"));
    }

    public void testReadBigFile() throws Exception {
        for (int i = 0; i < max; i++) {
            BufferedReader in = getReader();
            long t0 = System.currentTimeMillis();
            int count = readAll(in);
            in.close();
System.out.println("File read in " + (System.currentTimeMillis() - t0) + "ms" + " " + count + " lines");
        }
        System.out.println();
    }

    private int readAll(BufferedReader in) throws IOException {
        int count = 0;
        while (in.readLine() != null) {
            count++;
        }

        return count;
    }

    public void testParseBigFile() throws Exception {
        for (int i = 0; i < max; i++) {
            long t0 = System.currentTimeMillis();
            int count = parseCommonsCSV(getReader());
System.out.println("File parsed in " + (System.currentTimeMillis() - t0) + "ms with Commons CSV" + " " + count + " lines");
        }
        System.out.println();
    }

    private int parseCommonsCSV(Reader in) {
CSVFormat format = CSVFormat.DEFAULT.withSurroundingSpacesIgnored(false);

        int count = 0;
        for (String[] record : format.parse(in)) {
            count++;
        }

        return count;
    }
}


Emmanuel Bourg

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to