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 山風小子 閱讀(2310) 評論(5)  編輯  收藏 所屬分類: Groovy & Grails

          轉載文章,請保留原始鏈接和署名



          Dict.CN
          <2008年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          常用鏈接

          留言簿(71)

          隨筆分類

          隨筆檔案

          相冊

          Documentations

          Groovy & Grails

          友情鏈接

          好友 & 鄰居

          最新隨筆

          搜索

          •  

          積分與排名

          • 積分 - 795869
          • 排名 - 53

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 河北省| 麟游县| 瑞丽市| 宁安市| 巴青县| 仙桃市| 松阳县| 望城县| 循化| 台中市| 荣成市| 临潭县| 河西区| 石家庄市| 新绛县| 平罗县| 托里县| 德安县| 凤城市| 和平区| 赫章县| 阜阳市| 延长县| 宣汉县| 明光市| 噶尔县| 永善县| 九江县| 奎屯市| 天台县| 台东县| 德江县| 宣化县| 福鼎市| 龙陵县| 山西省| 资中县| 襄汾县| 宝应县| 江都市| 淮北市|