Brian Coyner: Did you know that you can throw null?
Go read Brian's post now.
Done? Good.
When I ran Brian's example on a three-year-old WinXP Pro SP2 Pentium 4 3.2GHz, 2.5 GB RAM, Java 6, I get the following results:
[weiqi@gao]$ java NullExceptionTest # throwNull
Average Time (nano): 18022
Average Time (nano): 17965
Average Time (nano): 19184
Average Time (nano): 17377
Average Time (nano): 16760
Average Time (nano): 16423
[weiqi@gao]$ java NullExceptionTest # throwNullPointerException
Average Time (nano): 3884
Average Time (nano): 3327
Average Time (nano): 2980
Average Time (nano): 2669
Average Time (nano): 3024
Average Time (nano): 2724
Throwing null is still more expensive than throwing a new NullPointerException, however the ratio is 5.68 rather than the 45 on Brian's machine.
Now I'm curious how the numbers will respond to arch/os/runtime variations.