0

I am in the middle of writing a XLSX parser. My usecase is just to read a spreadsheet and store the cell values into some object structure.

Once complete, I want to compare my code's performance (memory and time) with that of Apache Poi.

For time comparison, I was thinking of checking the delta System.nanotime(). I will parse the xlsx multiple times in a loop to make sure the execution time is in the order of seconds and then average.

I need help with the following:

  1. Is there a better way to compare execution time?
  2. How can I compare the memory footprint of my code with Poi?

Could anybody help with some information/suggestion please?

Hirak
  • 3,601
  • 1
  • 22
  • 33
  • Is your XLSX parser using Apache POI or is completely different and you want to benchmark your code against POI's execution time? – Luiggi Mendoza May 15 '14 at 15:32
  • Are you using Eclipse? – user184994 May 15 '14 at 15:32
  • @LuiggiMendoza I am parsing through plain vanilla sax parser. Not using any apache poi classes. And yes, I am using eclipse. – Hirak May 15 '14 at 15:34
  • The problem with doing this repeatedly is that is should be faster as the code warms up. How relativistic is this in your use case? Will you be loading multiple files, or much larger files? – Peter Lawrey May 15 '14 at 15:34
  • I will be loading files of about 1 to 2 MB in size. I just want read-cell value functionality. So I am trying to check if poi is worth using in such a simple usecase – Hirak May 15 '14 at 15:35
  • 1
    You should have a good gain in performance not using `POI` to have tried it myself. `POI` is nice and all but it isn't the cleanest or fastest thing just to read `xlsx` files. If you don't need to interpret formulas that is. – Jonathan Drapeau May 15 '14 at 15:41
  • yes I was thinking in the same line... – Hirak May 15 '14 at 15:44

1 Answers1

2

Is there a better way to compare execution time?

When writing your own micro benchmark, you should take into account the tips explained here: How do I write a correct micro-benchmark in Java?.

After reading that info, you should understand that is not that easy to write micro benchmarks by yourself. That's why there are micro benchmark libraries that eases this work like JUnitBenchmarks and Caliper.

How can I compare the memory footprint of my code with Poi?

I have used profilers to measure the memory used for the algorithms I have developed, but probably that's not what you're looking for. And the other approach you may use is by simply calculating runtime.totalMemory() - runtime.freeMemory(). You can find more info about how to get the memory footprint for your tests here: Java unit testing: how to measure memory footprint for method call

Community
  • 1
  • 1
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • I don't want re-invent... so thanks for pointing out the library. It is in "alpha" through... do you think that should be a concern? – Hirak May 15 '14 at 15:44
  • @Hirak well, I've used it and helped me to benchmark the performance of my algorithms. I also used a profiler to measure the time used when the application was live and the results were similar, so IMO the framework works as good as expected. There are other frameworks to do micro benchmark in Java, but I haven't found a link while writing the answer. – Luiggi Mendoza May 15 '14 at 15:47
  • @Hirak updated the answer by providing another micro benchmark framework. – Luiggi Mendoza May 15 '14 at 17:43