mike zeseler

张绍林

 

2009年2月8日

Groovy and Java

  Groovy and Java

posted @ 2009-04-19 10:49 mike zeseler 阅读(179) | 评论 (0)编辑 收藏

JDK 7 Twice as Fast* as JDK 6 for Arrays and Arithmetic

有时间我把它弄成中文的。
The 7th version of the Java Developer’s Kit (aka JDK 7) delivers quite a speed boost over JDK 6 array accesses. For us, this is huge. It’s like another year and a half of Moore’s law for free. Only in software. And you don’t even have to write multi-threaded code.

I’ve been profiling my new K-Means++ implementation for the next LingPipe release on some randomly generated data. It’s basically a stress test for array gets, array sets, and simple multiply-add arithmetic. Many LingPipe modules are like this at run-time: named entity, part-of-speech tagging, language modeling, LM-based classifiers, and much more.

While I was waiting for a run using JDK 1.6 to finish, I installed the following beta release of JDK 7:

> java -version
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b52)
Java HotSpot(TM) 64-Bit Server VM (build 15.0-b03, mixed mode)

You can get it, too:

I believe much of the reason it’s faster is the work of these fellows:

Java’s always suffered relative to C in straight matrix multiplication because Java does range checks on every array access (set or get). With some clever static and run-time analysis, Würthinger et al. are able to eliminate most of the array bounds checks. They show on matrix benchmarks that this one improvement doubles the speed of the LU matrix factorization benchmark in the U.S. National Institute of Standards (NIST) benchmark suite SciMark 2, which like our clustering algorithm, is basically just a stress test for array access and arithmetic.

So far, my tests have only been on a Thinkpad Z61P notebook running Windows Vista (64 bit) with an Intel Core 2 CPU (T2700; 2.0GHz), and 4GB of reasonably zippy memory. I don’t know if the speedups will be as great for other OSes or for 32-bit JDKs.

I’m pretty excited about the new fork-join concurrency, too, as it’s just what we’ll need to parallelize the inner loops without too much work for us or the operating system.

*Update: 2:30 PM, 30 March 2009 JDK 7 is only about 15% faster than Sun’s JDK 6 on my quad Xeons (E5410, 2.33GHz) at work running the same code. I’ll have to check the exact specs on both of my memory buses. The notebook has surprisingly fast memory and the Xeon’s running ECC registered memory that I don’t think is quite as fast.

Update: 11:00 AM, 31 March 2009 Like other matrix algorithms, k-means clustering is extremely front-side-bus sensitive (connection between memory and the CPU), because the bottleneck is often between memory and the CPU’s L2 cache. Memory’s significantly slower than CPU these days.

The Intel dual quad-core Xeon E5410 have 12MB of L2 cache at 2.3GHz, whereas the Thinkpad Z61P has Intel Core 2 Mobile T7200 has only 4MB of L2 cache at 2GHz. The Core 2 has a 667 MHz front-side bus whereas the Xeon reports a 1333 MHz front-side bus (is that just the confusion between spec reporting). I actually don’t know what kind of memory’s in the workstation — I’ll have to crack it open and look. I’ve got 4GB of RAM in the notebook, but the motherboard can only see 3GB (ithat is, it’s not Windows — the same thing happened when I installed Ubuntu on the notebook and it’s a known design limitation in many motherboards); I have 16GB of RAM in the workstation and the motherboard can see all of it. But it has two physical chips, each of which share the memory, so the motherboard’s architecture’s very different. There are so many confounding factors that I can’t tease apart what’s speeding up in JDK 7 so much on the notebook.

Anway, go forth and test. If you’re using a machine like my notebook to do number crunching, JDK 7 really is twice as fast as JDK 6 for matrix algorithms.

posted @ 2009-04-06 15:03 mike zeseler 阅读(204) | 评论 (0)编辑 收藏

hibernate入门更新完成

Hibernate入门指南

        今天抽咯时间完成咯自己没有完成的东西。
        希望大家多多支持我. 详细信息:
        参见http://www.blogjava.net/mikezeseler/archive/2009/01/15/251491.html 
                                  

                                                            Mike zeseler
                                                                                    

 

posted @ 2009-02-13 19:47 mike zeseler 阅读(596) | 评论 (0)编辑 收藏

groovy开发入门

自己软件开发经验不是很好,还须向大家学习!希望大家支持下我!有不足之处请大家批评指正。
 

Groovy就是java世界的动态语言

一:快速开始(gettingStart

安装JDK环境

Groovy需要JDK1.4以上版本的支持。因此在安装groovy时首先要安装JDK

JDK安装步骤:

     下载自己喜欢的JDK版本。(下载网址:http://java.sun.com

   下载Groovy

Groovy 下载首页截图

   
 

点击Download

进入下载页面

Groovy最新版本:Groovy 1.6-RC-2



 

我下载的是:Download Windows-Installer: Binary Release 安装版本

运行安装者

设置JAVA_HOME 环境变量. Windows平台里,步骤如下:

(1)打开系统"控制面板"

单击"高级"选项卡

单击"环境变量" 按钮

添加一个名称为"JAVA_HOME" 的新的系统环境变量,并且将你的Java的安装目录作为它的值 (例如,我的是C:"Program Files"Java"jdk1.6.0(版本号))

你也可以添加 %JAVA_HOME%"bin到你的系统的PATH变量中

(2)右击我的电脑属性

 

点击高级选项


 

点击环境变量

点击新建选项:

具体设置


 

Path


 

我用的Jdk版本是Jdk1.6

     运行安装文件。(更改安装路径到:C:"Program Files"Java"jdk1.6.0(版本号))

     设置JAVA_HOME环境变量(如我的

     在系统path中增加:%JAVA_HOME%"bin

注:对于1.1-rc-1以上版本需要JDK1.5版或更高的版本。

点击自己下载的Groovy windows安装版本
 

安装可以是默认的安装全点击下一步(next):

安装就完成啦

(Note: as an alternative to setting a system environment variable, you can create yourself a '.bat' or '.cmd' file which sets

the variable. You then need to run that batch file in any console window in which you wish to run Java and double clicking on

 

.bat' or '.cmd' files containing Java invocation instructions won't work. If you are unsure about what this means, follow

the earlier instructions.)

Note: JDK 1.5 is required for version 1.1-rc-1. In earlier versions of JDK (notably 1.4.2) the compiller throws an exception:

*nested exception is org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoSuchMethodError:

java.lang.String.replace(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String;

The method "replace" was introduced in JDK 1.5 and is not supportedin earlier versions. This is also a reason why GRails

framework doesn't run on JRE 1.4

(1)如果你是安装版本Groovy环境变量不需要我们设置,在安装的时候就自动设置好啦。

(2)如果不是,请自己尝试Groovy设置如下:

设置你的Groovy环境变量

从下载页面下载Groovy安装器或者二进制包,并且跟着介绍进行安装即可。(当前有一个问题,就是在windows下,你的安装路径不能含有空格

,即,要将其缺省的安装路径"c:"Program Files"Groovy" 改成象"c:"Groovy"这样的路径)

或者这样

从站点上得到Groovy发行版的copy,并且copy它到你硬盘上的某个地方。

解压缩这个groovy包到你硬盘的某个空间,如我的在 C:"dev"groovy-1.0-jsr-06

设置GROOVY_HOME环境变量. Windows下,作如下步骤:

添中新的系统环境变量GROOVY_HOME 并且将值设为你的groovy安装的路径( 我的是 C:"dev"groovy-1.0-jsr-06)

打开命令行窗口,并且键入"set" 然后打回车,查看你的环境变量设置是否已经正确。

可选的,你也可以添加 %GROOVY_HOME%"bin 到你的PATH环境变量中

通过双击试着运行groovyConsole.bat。如果它不能工作,打开一人命令行窗口,将目录改变到bin目录,并且运行它看他返回什么错误信息。

二:运行groovy

Groovy安装:目录


 

我们需要点击groovyConsole.bat文件:

文件详细内容如下:

@if "%DEBUG%" == "" @echo off

@rem

@rem $Revision: 2770 $ $Date: 2005-08-29 12:49:42 +0200 (Mo, 29. Aug 2005) $

@rem

@rem Set local scope for the variables with windows NT shell

if "%OS%"=="Windows_NT" setlocal

:begin

@rem Determine what directory it is in.

set DIRNAME=%~dp0

if "%DIRNAME%" == "" set DIRNAME=."

"%DIRNAME%"startGroovy.bat" "%DIRNAME%" groovy.ui.Console %*

@rem End local scope for the variables with windows NT shell

if "%OS%"=="Windows_NT" endlocal

安装完整无误的话 运行groovyConsole.bat就会启动groovyConsole.exe,出来一个编辑框。

 
 

上面的是文本输入框:根据groovy的语法输入要显示的内容:

下面的是内容输出框:显示上面的内容:

开始运行groovy


 

Hello, World

groovyConsole运行窗口的顶部,键入println "Hello, World!"

并且键入 <CTRL-R>.

注意,在控制台窗口中(即 groovyConsole窗口前面的黑色的那个),文体得到打印并且 groovyConsole的下部显示 :

groovy> println "Hello, World!"

null

 "groovy>"开头的行正是控制台处理的文本. "null" 是表达式的值. 因为表达式没有任何值可以打印 ,所以groovyConsole打印为"null"

接下来,再试一些实际的值,用下面的字符串来替换控制台里的文本:

123+45*67

或者你喜欢的任何表达式然后按<CTRL-R> (I'm going to stop telling you to hit <CTRL-R>, I think you get the idea). 现在, groovyConsole下面打印的值有更多的含义.

 

Variables

You can assign values to variables for later use. Try the following:x = 1

println x

x = new java.util.Date()

println x

x = -3.1499392

println x

x = false

println x

x = "Hi"

println x

Lists and Maps

The Groovy language has built-in support for two important data types, lists and maps (Lists can be operated as arrays in Java language). Lists are used to store ordered collections of data. For example an integer list of your favorite integers might look like this:myList = [1776, -1, 33, 99, 0, 928734928763]

You can access a given item in the list with square bracket notation (indexes start at 0):

println myList[0]

Should result in this output:

1776

You can get the length of the list with the "size" method:

println myList.size()

Should print out:

6

But generally you shouldn't need the length, because unlike Java, the preferred method to loop over all the elements in an list is to use the "each" method, which is described below in the "Code as Data" section.

Another native data structure is called a map. A map is used to store "associative arrays" or "dictionaries". That is unordered collections of heterogeneous, named data. For example, let's say we wanted to store names with IQ scores we might have:

scores = [ "Brett":100, "Pete":"Did not finish", "Andrew":86.87934 ]

Note that each of the values stored in the map is of a different type. Brett's is an integer, Pete's is a string, and Andrew's is a floating point number. We can access the values in a map in two main ways:

println scores["Pete"]

println scores.Pete

Should produce the output:

Did not finish

Did not finish

To add data to a map, the syntax is similar to adding values to an list. For example, if Pete re-took the IQ test and got a 3, we might:

scores["Pete"] = 3

Then later when we get the value back out, it will be 3.

println scores["Pete"]

should print out 3.

Also as an aside, you can create an empty map or an empty list with the following:

emptyMap = [:]

emptyList = []

To make sure the lists are empty, you can run the following lines:

println emptyMap.size()

println emptyList.size()

Should print a size of 0 for the List and the Map.

条件表达式

One of the most important features of any programming language is the ability to execute different code under different conditions. The simplest way to do this is to use the '''if''' construct. For example:amPM = Calendar.getInstance().get(Calendar.AM_PM)

if (amPM == Calendar.AM)

{

println("Good morning")

} else {

println("Good evening")

}

Don't worry too much about the first line, it's just some code to determine whether it is currently before noon or after. The rest of the code executes as follows: first it evaluates the expression in the parentheses, then depending on whether the result is '''true''' or '''false''' it executes the first or the second code block. See the section below on boolean expressions.

Note that the "else" block is not required, but the "then" block is:

amPM = Calendar.getInstance().get(Calendar.AM_PM)

if (amPM == Calendar.AM)

{

println("Have another cup of coffee.")

}

Boolean表达式

There is a special data type in most programming languages that is used to represent truth values, '''true''' and '''false'''. The simplest boolean expression are simply those words. Boolean values can be stored in variables, just like any other data type:myBooleanVariable = true

A more complex boolean expression uses one of the boolean operators:

==

!=

>

>=

<

<=

Most of those are probably pretty intuitive. The equality operator is '''==''' to distinguish from the assignment operator '''='''. The opposite of equality is the '''!=''' operator, that is "not equal"

So some examples:

titanicBoxOffice = 1234600000

titanicDirector = "James Cameron"

trueLiesBoxOffice = 219000000

trueLiesDirector = "James Cameron"

returnOfTheKingBoxOffice = 752200000

returnOfTheKingDirector = "Peter Jackson"

theTwoTowersBoxOffice = 581200000

theTwoTowersDirector = "PeterJackson"

titanicBoxOffice > returnOfTheKingBoxOffice // evaluates to true

titanicBoxOffice >= returnOfTheKingBoxOffice // evaluates to true

titanicBoxOffice >= titanicBoxOffice // evaulates to true

titanicBoxOffice > titanicBoxOffice // evaulates to false

titanicBoxOffice + trueLiesBoxOffice < returnOfTheKingBoxOffice + theTwoTowersBoxOffice // evaluates to false

titanicDirector > returnOfTheKingDirector // evaluates to false, because "J" is before "P"

titanicDirector < returnOfTheKingDirector // evaluates to true

titanicDirector >= "James Cameron" // evaluates to true

titanicDirector == "James Cameron" // evaluates to true

Boolean expressions are especially useful when used in conjunction with the '''if''' construct. For example:

if (titanicBoxOffice + trueLiesBoxOffice > returnOfTheKingBoxOffice + theTwoTowersBoxOffice)

{

println(titanicDirector + " is a better director than " + returnOfTheKingDirector)

}

An especially useful test is to test whether a variable or expression is null (has no value). For example let's say we want to see whether a given key is in a map:

suvMap = ["Acura MDX":""$36,700", "Ford Explorer":""$26,845"]

if (suvMap["Hummer H3"] != null)

{

println("A Hummer H3 will set you back "+suvMap["Hummer H3"]);

}

Generally null is used to indicate the lack of a value in some location.

Debugging and Troubleshooting Tips

Print out the class of a variable that you're interested in with myVar.getClass(). Then look up the documentation for that class.

If you're having trouble with a complex expression, pare it down to a simpler expression and evaluate that. Then build up to your more complex expression.

Try restarting the groovyConsole (this will clear out all the variables so you can start over.

Look for the topic you're interested in in the Groovy User Guide

If you are a Java developer

you might want to check on the Differences from Java

also there afew a few Things to remember

Labels parameters    

posted @ 2009-02-08 12:20 mike zeseler 阅读(2982) | 评论 (5)编辑 收藏

导航

统计

常用链接

留言簿(2)

随笔分类

随笔档案

文章档案

.net

“美少女股神”王雅媛

blogjava

books

dzineblog

europe open source

flash

google

j2EE

open erp

open source

Open Source Web Design

seo

seo 国外

sex

sns

Tiobe

w3c

web

Web 前端开发

web 设计blog

web2.0

web-design resource

兄弟软件

免费电子书

博客园

友情链接

建站

开源项目

房产博客

源码

计算机书籍下载站

音乐论坛

搜索

最新评论

阅读排行榜

评论排行榜