dev@grizzly.java.net

a question on enum performance

From: <Shing-Wai.Chan_at_Sun.COM>
Date: Wed, 12 Dec 2007 11:58:26 -0800

Hi,

 From code review comments, there is a concern about
the performance of using enum.
I have try to measure this by myself (see attached programs)
and see the following:

elliptic: /home/swchan2/doc/grizzly > java EnumTest
time for int[10] (ms): 0
time for type[10] (ms): 1

time for int[100] (ms): 0
time for type[100] (ms): 0

time for int[1000] (ms): 0
time for type[1000] (ms): 0

time for int[10000] (ms): 2
time for type[10000] (ms): 2

time for int[100000] (ms): 0
time for type[100000] (ms): 11

time for int[1000000] (ms): 0
time for type[1000000] (ms): 2

time for int[10000000] (ms): 0
time for type[10000000] (ms): 18

There is no doubt that enum is a bit slower than using static final int.
But is it significant?
Should we avoid using enum in our code in this case?
Any comment?

Thanks.
      Shing Wai Chan