First they ignore you
          then they ridicule you
          then they fight you
          then you win
              -- Mahatma Gandhi
          Chinese => English     英文 => 中文             
          隨筆-221  評論-1047  文章-0  trackbacks-0
          Groovy 1.6.0 BETA 1終于發布了,除了一些BUG修正外,最令人興奮的是,Groovy的運行效率有了顯著的提升。官方用Great Language Shootout的基準測試得出Groovy 1.6.0 BETA 1的性能相比Groovy 1.5.6 GA,提升了150%~460%。

          眼見為實,耳聽為虛,我自己也做了一個相對簡單的性能測試:

          利用Groovy 1.6.0 BETA 1將下面解決八皇后問題的代碼執行10次,結果如下:
          ????????????????????? 1???? 2???? 3???? 4???? 5???? 6???? 7???? 8???? 9??? 10??????????? AVG
          Groovy1.5.6GA?? :? 1360? 1156?? 969? 1000? 1063? 1110?? 938? 1046? 1031?? 954???????? 1062.7
          Groovy1.6.0BETA1:?? 187?? 171?? 141 ? 109 ? 187 ? 156 ? 172 ? 141 ? 203 ? 187????????? 165.4

          經過計算,Groovy1.6.0BETA1的性能相比Groovy1.5.6GA,提升了542.5%


          如果是普通應用程序代碼的話,提升的幅度會小一點。


          此外,Groovy1.6.0BETA1還支持Multiple assignments(多重賦值)
          def?listOfN(numOfElem)?{?
          ????
          1..numOfElem?
          }

          def?a,?b
          [a,?b]?
          =?listOfN(1)?
          assert?a?==?1
          assert?b?==?null

          [a,?b]?
          =?listOfN(10)?
          assert?a?==?1
          assert?b?==?2

          [a,?b]?
          =?[b,?a]
          assert?a?==?2
          assert?b?==?1

          還支持Annotations的定義,(在Groovy 1.6.0之前,Annotations的定義只能放在Java代碼中):
          @interface?Cachable?{
          ????String?cache()
          }

          最后一個值得關注的新特性就是引入@Bindable這個Annotation
          具體使用方法請參考: Groovy高效編程——@Bindable的使用


          八皇后問題代碼:
          q = 8
          i = new int[q]
          count = 0

          def scan(n){
          ??? if (n == q){
          ??????? println(i.toList())
          ??????? count++
          ??????? return
          ??? }
          ??? i[n]=0
          ??? while (i[n] < q){
          ??????? i[n] = i[n]+1
          ??????? if (check(n))
          ??????????? scan(n + 1)
          ??? }
          }
          def check(n){
          ??? if (n > 0)
          ??????? for (j in 0..<n)
          ??????????? if (i[j] == i[n] || i[j] - i[n] == j - n || i[j] - i[n] == n - j)
          ??????????????? return false
          ??? return true
          }

          long t1 = System.currentTimeMillis()
          scan(0)
          long t2 = System.currentTimeMillis()
          println("total time:" + ( t2 - t1))? // 耗時
          println("total results:" + count)

          下載地址:http://dist.groovy.codehaus.org/distributions/groovy-binary-1.6-beta-1.zip

          附:朝花夕拾——Groovy & Grails
          posted on 2008-05-03 11:52 山風小子 閱讀(2309) 評論(5)  編輯  收藏 所屬分類: Groovy & Grails
          主站蜘蛛池模板: 黄陵县| 潮安县| 余庆县| 安宁市| 大冶市| 敖汉旗| 南宁市| 泽州县| 虹口区| 旺苍县| 长海县| 民县| 泽库县| 丰宁| 若羌县| 安新县| 定襄县| 灵丘县| 彰化市| 航空| 民勤县| 马龙县| 丰城市| 汽车| 攀枝花市| 尼木县| 芜湖市| 雅安市| 库伦旗| 宜城市| 武清区| 郯城县| 青龙| 包头市| 福建省| 即墨市| 新乡县| 六盘水市| 英超| 手机| 伊宁县|