Repository navigation
Home
wenshao edited this page Feb 21, 2013
·
38 revisions
Java基本操作性能
执行环境:
java 6 version "1.6.0_29"
java 7 version "1.7.0_04-b20"
Linux 2.6.32 x86_64
Intel(R) Xeon(R) CPU E5420 @ 2.50GHz
<tr>
<td>AtomicInteger.increment</td>
<td>17</td>
<td>17</td>
<td> </td>
</tr>
<tr>
<td>AtomicLong.increment</td>
<td>17</td>
<td>17</td>
<td> </td>
</tr>
<tr>
<td>HashMap.get()</td>
<td>15</td>
<td>13</td>
<td>Key类型为String, size 1000</td>
</tr>
<tr>
<td>System.currentTimeMillis</td>
<td>52</td>
<td>52</td>
<td>linux 2.6.32之前的版本会慢10倍,大约534ns</td>
</tr>
<tr>
<td>System.nanoTime</td>
<td>47</td>
<td>47</td>
<td>linux 2.6.32之前的版本会慢12倍,大约658ns</td>
</tr>
<tr>
<td>ReentrantLock.lockFair</td>
<td>38</td>
<td>38</td>
<td> </td>
</tr>
<tr>
<td>ReentrantLock.lock</td>
<td>37</td>
<td>37</td>
<td> </td>
</tr>
<tr>
<td>synchronized</td>
<td>36</td>
<td>36</td>
<td> </td>
</tr>
<tr>
<td>Reflect.newInstance</td>
<td>15</td>
<td>12</td>
<td> </td>
</tr>
<tr>
<td>Reflect.invoke</td>
<td>9</td>
<td>6</td>
<td> 缓存了Method对象 </td>
</tr>
<tr>
<td>Reflect.Field.get</td>
<td>23</td>
<td>21</td>
<td> 缓存了Field对象 </td>
</tr>
<tr>
<td>Exception.new</td>
<td>1141</td>
<td>1061</td>
<td> new Exception() </td>
</tr>
<tr>
<td>Exception.newAndGetStackTrace</td>
<td>6798</td>
<td>5786</td>
<td> new Exception().getStackTrace() </td>
</tr>
<tr>
<td>Thread.getStackTrace</td>
<td>7707</td>
<td>6560</td>
<td> Thread.currentThread().getStackTrace() </td>
</tr>
<tr>
<td>Exception.new-throw-catch</td>
<td>1137</td>
<td>1092</td>
<td> new Exception(), throw, catch </td>
</tr>
<tr>
<td>Exception.new-throw-catch (none fillInStackTrace) </td>
<td>23</td>
<td>23</td>
<td> new Exception(), throw, catch,重载了fillStackTrace方法 </td>
</tr>
<tr>
<td>Exception.throw-catch</td>
<td>9</td>
<td>9</td>
<td>throw, catch,抛出的是同一个Exception</td>
</tr>
| 操作 | JDK 6 耗时(nano) | JDK 7 耗时(nano) | 说明 |
| volatile int ++ | 15 | 15 | volatile int |
| volatile long ++ | 15 | 15 | volatile long |