Skip to content
Browse files

merge from master

  • Loading branch information...
2 parents 9057be3 + 42186ec commit 322578724aac0b5d7a60e85313471e1046c766ba @paulk-asert paulk-asert committed Mar 31, 2012
Showing with 4,010 additions and 2,942 deletions.
  1. +16 −16 .classpath
  2. +23 −22 .externalToolBuilders/Groovy ensureGrammars.launch
  3. +0 −1 .project
  4. +9 −11 benchmark/bench/ackermann.groovy
  5. +4 −4 benchmark/bench/ackermann.java
  6. +9 −9 benchmark/bench/ary.groovy
  7. +9 −9 benchmark/bench/ary.java
  8. +49 −48 benchmark/bench/binarytrees.groovy
  9. +63 −63 benchmark/bench/binarytrees.java
  10. +123 −123 benchmark/bench/chameneos.java
  11. +49 −49 benchmark/bench/echo.java
  12. +29 −29 benchmark/bench/except.java
  13. +7 −6 benchmark/bench/fannkuch.groovy
  14. +21 −21 benchmark/bench/fannkuchredux.java
  15. +4 −4 benchmark/bench/fibo.java
  16. +18 −18 benchmark/bench/hash.java
  17. +21 −21 benchmark/bench/hash2.java
  18. +43 −43 benchmark/bench/heapsort.groovy
  19. +40 −40 benchmark/bench/heapsort.java
  20. +6 −9 benchmark/bench/hello.groovy
  21. +1 −1 benchmark/bench/hello.java
  22. +97 −97 benchmark/bench/knucleotide.java
  23. +47 −47 benchmark/bench/lists.java
  24. +36 −46 benchmark/bench/mandelbrot.groovy
  25. +32 −32 benchmark/bench/matrix.java
  26. +26 −26 benchmark/bench/methcall.java
  27. +154 −154 benchmark/bench/nbody.java
  28. +10 −10 benchmark/bench/nestedloop.java
  29. +34 −33 benchmark/bench/nsieve.groovy
  30. +30 −30 benchmark/bench/objinst.java
  31. +8 −15 benchmark/bench/random.groovy
  32. +10 −10 benchmark/bench/random.java
  33. +77 −77 benchmark/bench/raytracer.java
  34. +25 −26 benchmark/bench/recursive.groovy
  35. +40 −34 benchmark/bench/regexdna.groovy
  36. +51 −52 benchmark/bench/revcomp.groovy
  37. +24 −18 benchmark/bench/revcomp.java
  38. +19 −19 benchmark/bench/sieve.java
  39. +17 −21 benchmark/bench/spectralnorm.groovy
  40. +69 −69 benchmark/bench/spectralnorm.java
  41. +17 −17 benchmark/bench/spellcheck.java
  42. +5 −5 benchmark/bench/strcat.java
  43. +8 −8 benchmark/bench/takfp.java
  44. +46 −46 benchmark/bench/threadring.groovy
  45. +1 −1 benchmark/bench/wc.java
  46. +12 −29 benchmark/bench/wordfreq.groovy
  47. +7 −6 benchmark/bench/wordfreq.java
  48. +7 −8 build.gradle
  49. +2 −0 build.properties
  50. +37 −14 build.xml
  51. +18 −18 config/codenarc/codenarc.groovy
  52. +3 −2 config/maven/groovy-tools.pom
  53. +11 −10 pom.xml
  54. +12 −12 src/main/groovy/lang/GroovyClassLoader.java
  55. +5 −5 src/main/groovy/lang/MetaClassImpl.java
  56. +11 −11 src/main/groovy/util/GroovyScriptEngine.java
  57. +29 −29 src/main/org/codehaus/groovy/antlr/java/Groovifier.java
  58. +202 −202 src/main/org/codehaus/groovy/antlr/java/Java2GroovyConverter.java
  59. +3 −3 src/main/org/codehaus/groovy/antlr/java/Java2GroovyMain.java
  60. +69 −69 src/main/org/codehaus/groovy/antlr/java/PreJava2GroovyConverter.java
  61. +9 −0 src/main/org/codehaus/groovy/ast/CompileUnit.java
  62. +8 −8 src/main/org/codehaus/groovy/ast/expr/MethodCallExpression.java
  63. +4 −4 src/main/org/codehaus/groovy/ast/tools/WideningCategories.java
  64. +65 −67 src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
  65. +26 −13 src/main/org/codehaus/groovy/classgen/asm/BinaryExpressionHelper.java
  66. +22 −12 src/main/org/codehaus/groovy/classgen/asm/BinaryExpressionMultiTypeDispatcher.java
  67. +179 −179 src/main/org/codehaus/groovy/classgen/asm/CompileStack.java
  68. +6 −6 src/main/org/codehaus/groovy/classgen/asm/InvocationWriter.java
  69. +14 −9 src/main/org/codehaus/groovy/classgen/asm/StatementWriter.java
  70. +24 −2 src/main/org/codehaus/groovy/classgen/asm/WriterController.java
  71. +204 −0 src/main/org/codehaus/groovy/classgen/asm/indy/InvokeDynamicWriter.java
  72. +46 −6 src/main/org/codehaus/groovy/control/CompilationUnit.java
  73. +4 −0 src/main/org/codehaus/groovy/reflection/ParameterTypes.java
  74. +2 −0 src/main/org/codehaus/groovy/reflection/ReflectionUtils.java
  75. +8 −8 src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
  76. +33 −33 src/main/org/codehaus/groovy/runtime/GroovyCategorySupport.java
  77. +6 −6 src/main/org/codehaus/groovy/runtime/InvokerHelper.java
  78. +8 −10 src/main/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java
  79. +5 −3 src/main/org/codehaus/groovy/runtime/callsite/GroovySunClassLoader.java
  80. +23 −0 src/main/org/codehaus/groovy/runtime/metaclass/DefaultMetaClassInfo.java
  81. +1 −0 src/main/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java
  82. +4 −0 src/main/org/codehaus/groovy/runtime/metaclass/ReflectionMetaMethod.java
  83. +2 −2 src/main/org/codehaus/groovy/runtime/metaclass/TemporaryMethodKey.java
  84. +1 −1 src/main/org/codehaus/groovy/tools/DgmConverter.java
  85. +1 −0 src/main/org/codehaus/groovy/tools/FileSystemCompiler.java
  86. +11 −11 src/main/org/codehaus/groovy/tools/javac/JavaAwareCompilationUnit.java
  87. +4 −4 src/main/org/codehaus/groovy/transform/StaticTypesTransformation.java
  88. +23 −23 src/main/org/codehaus/groovy/transform/stc/SharedVariableCollector.java
  89. +2 −2 src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
  90. +66 −69 src/main/org/codehaus/groovy/vmplugin/VMPluginFactory.java
  91. +699 −0 src/main/org/codehaus/groovy/vmplugin/v7/IndyInterface.java
  92. +2 −2 src/test-resources/stubgenerator/circularLanguageReference/Shape.java
  93. +4 −4 src/test-resources/stubgenerator/circularLanguageReference/Square.java
  94. +2 −2 src/test/gls/generics/GenericsTestBase.java
  95. +1 −1 src/test/groovy/StaticImportTarget.groovy
  96. +1 −1 src/test/groovy/bugs/Groovy3208Bug.groovy
  97. +2 −2 src/test/groovy/bugs/Groovy3465Helper.groovy
  98. +27 −27 src/test/groovy/bugs/Groovy5030Bug.groovy
  99. +3 −3 src/test/groovy/bugs/Groovy5033Bug.groovy
  100. +38 −38 src/test/groovy/bugs/Groovy5056Bug.groovy
  101. +18 −18 src/test/groovy/bugs/Groovy5193Bug.groovy
  102. +27 −27 src/test/groovy/bugs/VerifyErrorBug.groovy
  103. +2 −2 src/test/groovy/lang/MixinAnnotationTest.groovy
  104. +3 −3 src/test/groovy/lang/MixinTest.groovy
  105. +60 −60 src/test/org/codehaus/groovy/benchmarks/vm5/spectralnorm.java
  106. +4 −3 src/test/org/codehaus/groovy/classgen/DumpingClassLoader.java
  107. +2 −2 src/test/org/codehaus/groovy/classgen/JO.java
  108. +12 −31 src/test/org/codehaus/groovy/classgen/asm/AbstractBytecodeTestCase.groovy
  109. +1 −1 src/test/org/codehaus/groovy/control/customizers/SecureASTCustomizerTest.groovy
  110. +278 −223 subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
  111. +4 −2 subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/VerifyClass.java
  112. +2 −2 subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/ScriptToTreeNodeAdapter.groovy
  113. +1 −1 subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy
  114. +3 −3 ...ojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/ReflectionCompletor.groovy
  115. +21 −21 subprojects/groovy-swing/src/main/groovy/groovy/swing/factory/CellEditorFactory.groovy
  116. +31 −31 subprojects/groovy-swing/src/main/groovy/groovy/swing/factory/ColumnFactory.groovy
  117. +96 −96 subprojects/groovy-swing/src/main/groovy/groovy/swing/impl/ClosureCellEditor.groovy
View
32 .classpath
@@ -9,39 +9,39 @@
<classpathentry kind="src" output="bin" path="subprojects/groovy-jmx/src/test/groovy"/>
<classpathentry kind="src" output="bin" path="subprojects/groovy-jmx/src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
- <classpathentry kind="var" path="M2_REPO/org/apache/ant/ant/1.8.1/ant-1.8.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/ant/ant/1.8.2/ant-1.8.2.jar"/>
<classpathentry kind="var" path="M2_REPO/javax/servlet/jsp-api/2.0/jsp-api-2.0.jar"/>
- <classpathentry kind="var" path="M2_REPO/asm/asm-tree/3.2/asm-tree-3.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/ow2/asm/asm/4.0/asm-4.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/ow2/asm/asm-analysis/4.0/asm-analysis-4.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/ow2/asm/asm-commons/4.0/asm-commons-4.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/ow2/asm/asm-tree/4.0/asm-tree-4.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/ow2/asm/asm-util/4.0/asm-util-4.0.jar"/>
<classpathentry kind="var" path="M2_REPO/javax/servlet/servlet-api/2.4/servlet-api-2.4.jar" sourcepath="M2_REPO/javax/servlet/servlet-api/2.4/servlet-api-2.4-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/bsf/bsf/2.4.0/bsf-2.4.0.jar"/>
- <classpathentry kind="var" path="M2_REPO/antlr/antlr/2.7.6/antlr-2.7.6.jar"/>
+ <classpathentry kind="var" path="M2_REPO/antlr/antlr/2.7.7/antlr-2.7.7.jar"/>
<classpathentry kind="var" path="M2_REPO/jmock/jmock-cglib/1.2.0/jmock-cglib-1.2.0.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-junit/1.8.2/ant-junit-1.8.2.jar"/>
- <classpathentry kind="var" path="M2_REPO/commons-cli/commons-cli/1.0/commons-cli-1.0.jar"/>
- <classpathentry kind="var" path="M2_REPO/hsqldb/hsqldb/1.8.0.7/hsqldb-1.8.0.7.jar"/>
- <classpathentry kind="var" path="M2_REPO/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/asm/asm-analysis/3.2/asm-analysis-3.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-cli/commons-cli/1.2/commons-cli-1.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/hsqldb/hsqldb/1.8.0.10/hsqldb-1.8.0.10.jar"/>
+ <classpathentry kind="var" path="M2_REPO/com/thoughtworks/xstream/xstream/1.4.1/xstream-1.4.1.jar"/>
<classpathentry kind="var" path="M2_REPO/cglib/cglib-nodep/2.1_3/cglib-nodep-2.1_3.jar"/>
<classpathentry kind="var" path="M2_REPO/jmock/jmock/1.2.0/jmock-1.2.0.jar"/>
<classpathentry kind="var" path="M2_REPO/openejb/openejb-loader/1.0/openejb-loader-1.0.jar"/>
- <classpathentry kind="var" path="M2_REPO/asm/asm/3.2/asm-3.2.jar"/>
- <classpathentry kind="var" path="M2_REPO/asm/asm-util/3.2/asm-util-3.2.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-launcher/1.8.1/ant-launcher-1.8.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-launcher/1.8.2/ant-launcher-1.8.2.jar"/>
<classpathentry kind="lib" path="security/GroovyJarTest.jar"/>
<classpathentry kind="var" path="M2_REPO/jline/jline/0.9.94/jline-0.9.94.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-testutil/1.8.2/ant-testutil-1.8.2.jar"/>
- <classpathentry kind="var" path="M2_REPO/junit/junit/4.8.2/junit-4.8.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/4.10/junit-4.10.jar"/>
<classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"/>
<classpathentry kind="var" path="M2_REPO/xmlunit/xmlunit/1.3/xmlunit-1.3.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/fusesource/jansi/jansi/1.2.1/jansi-1.2.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/fusesource/jansi/jansi/1.7/jansi-1.7.jar"/>
<classpathentry kind="var" path="M2_REPO/ch/qos/logback/logback-classic/0.9.21/logback-classic-0.9.21.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/objectweb/asm/com.springsource.org.objectweb.asm.commons/2.2.3/com.springsource.org.objectweb.asm.commons-2.2.3.jar"/>
- <classpathentry kind="var" path="M2_REPO/com/thoughtworks/qdox/qdox/1.8/qdox-1.8.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/com/thoughtworks/qdox/qdox/1.12/qdox-1.12.jar"/>
<classpathentry kind="var" path="M2_REPO/ch/qos/logback/logback-core/0.9.21/logback-core-0.9.21.jar"/>
<classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.16/log4j-1.2.16.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.6.0/slf4j-api-1.6.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/slf4j/jcl-over-slf4j/1.6.0/jcl-over-slf4j-1.6.0.jar"/>
<classpathentry kind="lib" path="target/classes"/>
<classpathentry kind="output" path="bin"/>
</classpath>
View
45 .externalToolBuilders/Groovy ensureGrammars.launch
@@ -1,22 +1,23 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
-<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="ensureGrammars,"/>
-<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="ensureGrammars,"/>
-<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
-<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
-<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
-<listEntry value="/groovy/build.xml"/>
-</listAttribute>
-<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
-<listEntry value="1"/>
-</listAttribute>
-<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
-<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
-<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
-<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
-<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="groovy"/>
-<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/groovy/build.xml}"/>
-<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/>
-<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
-<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${project_loc:/groovy}"/>
-</launchConfiguration>
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
+<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="ensureGrammars,"/>
+<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="ensureGrammars,"/>
+<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
+<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/groovy/build.xml"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="1"/>
+</listAttribute>
+<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
+<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
+<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
+<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value=""/>
+<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="true"/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${project_loc:build.xml}"/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/>
+<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${project_loc:}"/>
+</launchConfiguration>
View
1 .project
@@ -24,6 +24,5 @@
<natures>
<nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.codehaus.groovy.eclipse.groovyNature</nature>
</natures>
</projectDescription>
View
20 benchmark/bench/ackermann.groovy
@@ -1,18 +1,16 @@
/*
-The Computer Language Shootout
-http://shootout.alioth.debian.org/
-
-contributed by Jochen Hinrichsen
-*/
+ * The Computer Language Shootout
+ * http://shootout.alioth.debian.org/
+ *
+ * contributed by Jochen Hinrichsen
+ */
def A(x, y) {
- // TODO: return statement is stated optional, but does not work w/o
- if (x == 0) return y+1
- if (y == 0) return A(x-1, 1)
- return A(x-1, A(x, y-1))
+ if (x == 0) return y+1
+ if (y == 0) return A(x-1, 1)
+ return A(x-1, A(x, y-1))
}
-def n = this.args[0].toInteger()
+def n = args[0].toInteger()
def result = A(3, n)
println("Ack(3,${n}): ${result}")
-
View
8 benchmark/bench/ackermann.java
@@ -3,11 +3,11 @@
public class ackermann {
public static void main(String[] args) {
- int num = Integer.parseInt(args[0]);
- System.out.println("Ack(3," + num + "): " + Ack(3, num));
+ int num = Integer.parseInt(args[0]);
+ System.out.println("Ack(3," + num + "): " + Ack(3, num));
}
public static int Ack(int m, int n) {
- return (m == 0) ? (n + 1) : ((n == 0) ? Ack(m-1, 1) :
- Ack(m-1, Ack(m, n - 1)));
+ return (m == 0) ? (n + 1) : ((n == 0) ? Ack(m-1, 1) :
+ Ack(m-1, Ack(m, n - 1)));
}
}
View
18 benchmark/bench/ary.groovy
@@ -10,16 +10,16 @@
public class ary {
public static void main(String[] args) {
- int i, j, k, n = Integer.parseInt(args[0]);
- int[] x = new int[n];
- int[] y = new int[n];
+ int i, j, k, n = Integer.parseInt(args[0]);
+ int[] x = new int[n];
+ int[] y = new int[n];
- for (i = 0; i < n; i++)
- x[i] = i + 1;
- for (k = 0; k < 1000; k++ )
- for (j = n-1; j >= 0; j--)
- y[j] += x[j];
+ for (i = 0; i < n; i++)
+ x[i] = i + 1;
+ for (k = 0; k < 1000; k++ )
+ for (j = n-1; j >= 0; j--)
+ y[j] += x[j];
- System.out.println(y[0] + " " + y[n-1]);
+ System.out.println(y[0] + " " + y[n-1]);
}
}
View
18 benchmark/bench/ary.java
@@ -12,16 +12,16 @@
public class ary {
public static void main(String args[]) {
- int i, j, k, n = Integer.parseInt(args[0]);
- int x[] = new int[n];
- int y[] = new int[n];
+ int i, j, k, n = Integer.parseInt(args[0]);
+ int x[] = new int[n];
+ int y[] = new int[n];
- for (i = 0; i < n; i++)
- x[i] = i + 1;
- for (k = 0; k < 1000; k++ )
- for (j = n-1; j >= 0; j--)
- y[j] += x[j];
+ for (i = 0; i < n; i++)
+ x[i] = i + 1;
+ for (k = 0; k < 1000; k++ )
+ for (j = n-1; j >= 0; j--)
+ y[j] += x[j];
- System.out.println(y[0] + " " + y[n-1]);
+ System.out.println(y[0] + " " + y[n-1]);
}
}
View
97 benchmark/bench/binarytrees.groovy
@@ -1,63 +1,64 @@
-/* The Computer Language Benchmarks Game
- http://shootout.alioth.debian.org/
- contributed by Jochen Hinrichsen
- modified by Marko Kocic
-*/
+/*
+ * The Computer Language Benchmarks Game
+ * http://shootout.alioth.debian.org/
+ *
+ * contributed by Jochen Hinrichsen
+ * modified by Marko Kocic
+ */
final class TreeNode {
- private final left, right, item
-
- TreeNode(item){
- this.item = item
- }
-
- private static bottomUpTree(item, depth) {
- if (depth>0) {
- return new TreeNode(
- bottomUpTree(2*item-1, depth-1)
- , bottomUpTree(2*item, depth-1)
- , item
- )
- } else {
- return new TreeNode(item)
- }
- }
-
- TreeNode(left, right, item){
- this.left = left
- this.right = right
- this.item = item
- }
-
- private itemCheck(){
- // if necessary deallocate here
- if (left==null) return item
- else return item + left.itemCheck() - right.itemCheck()
- }
-}
+ private final left, right, item
+
+ TreeNode(item) {
+ this.item = item
+ }
+
+ private static bottomUpTree(item, depth) {
+ if (depth > 0) {
+ return new TreeNode(
+ bottomUpTree(2*item-1, depth-1),
+ bottomUpTree(2*item, depth-1),
+ item
+ )
+ } else {
+ return new TreeNode(item)
+ }
+ }
+ TreeNode(left, right, item) {
+ this.left = left
+ this.right = right
+ this.item = item
+ }
+
+ private itemCheck() {
+ // if necessary deallocate here
+ if (left == null) return item
+ else return item + left.itemCheck() - right.itemCheck()
+ }
+}
def n = (args.length == 0) ? 10 : args[0].toInteger()
def minDepth = 4
-def maxDepth = [ minDepth + 2, n].max()
+def maxDepth = [minDepth + 2, n].max()
def stretchDepth = maxDepth + 1
-def check = (TreeNode.bottomUpTree(0,stretchDepth)).itemCheck()
+def check = (TreeNode.bottomUpTree(0, stretchDepth)).itemCheck()
println "stretch tree of depth ${stretchDepth}\t check: ${check}"
-def longLivedTree = TreeNode.bottomUpTree(0,maxDepth)
+def longLivedTree = TreeNode.bottomUpTree(0, maxDepth)
-def depth=minDepth
-while (depth<=maxDepth) {
- def iterations = 1 << (maxDepth - depth + minDepth)
- check = 0
- for (i in 1..iterations) {
- check += (TreeNode.bottomUpTree(i,depth)).itemCheck()
- check += (TreeNode.bottomUpTree(-i,depth)).itemCheck()
- }
+def depth = minDepth
+while (depth <= maxDepth) {
+ def iterations = 1 << (maxDepth - depth + minDepth)
+ check = 0
+ for (i in 1..iterations) {
+ check += (TreeNode.bottomUpTree(i, depth)).itemCheck()
+ check += (TreeNode.bottomUpTree(-i,depth)).itemCheck()
+ }
- println "${iterations*2}\t trees of depth ${depth}\t check: ${check}"
- depth+=2
+ println "${iterations*2}\t trees of depth ${depth}\t check: ${check}"
+ depth += 2
}
println "long lived tree of depth ${maxDepth}\t check: ${longLivedTree.itemCheck()}"
View
126 benchmark/bench/binarytrees.java
@@ -1,71 +1,71 @@
/* The Great Computer Language Shootout
http://shootout.alioth.debian.org/
-
+
contributed by Jarkko Miettinen
*/
public class binarytrees {
- private final static int minDepth = 4;
-
- public static void main(String[] args){
- int n = 0;
- if (args.length > 0) n = Integer.parseInt(args[0]);
-
- int maxDepth = (minDepth + 2 > n) ? minDepth + 2 : n;
- int stretchDepth = maxDepth + 1;
-
- int check = (TreeNode.bottomUpTree(0,stretchDepth)).itemCheck();
- System.out.println("stretch tree of depth "+stretchDepth+"\t check: " + check);
-
- TreeNode longLivedTree = TreeNode.bottomUpTree(0,maxDepth);
-
- for (int depth=minDepth; depth<=maxDepth; depth+=2){
- int iterations = 1 << (maxDepth - depth + minDepth);
- check = 0;
-
- for (int i=1; i<=iterations; i++){
- check += (TreeNode.bottomUpTree(i,depth)).itemCheck();
- check += (TreeNode.bottomUpTree(-i,depth)).itemCheck();
- }
- System.out.println((iterations*2) + "\t trees of depth " + depth + "\t check: " + check);
- }
- System.out.println("long lived tree of depth " + maxDepth + "\t check: "+ longLivedTree.itemCheck());
- }
-
-
- private static class TreeNode
- {
- private TreeNode left, right;
- private int item;
-
- TreeNode(int item){
- this.item = item;
- }
-
- private static TreeNode bottomUpTree(int item, int depth){
- if (depth>0){
- return new TreeNode(
- bottomUpTree(2*item-1, depth-1)
- , bottomUpTree(2*item, depth-1)
- , item
- );
- }
- else {
- return new TreeNode(item);
- }
- }
-
- TreeNode(TreeNode left, TreeNode right, int item){
- this.left = left;
- this.right = right;
- this.item = item;
- }
-
- private int itemCheck(){
- // if necessary deallocate here
- if (left==null) return item;
- else return item + left.itemCheck() - right.itemCheck();
- }
- }
+ private final static int minDepth = 4;
+
+ public static void main(String[] args){
+ int n = 0;
+ if (args.length > 0) n = Integer.parseInt(args[0]);
+
+ int maxDepth = (minDepth + 2 > n) ? minDepth + 2 : n;
+ int stretchDepth = maxDepth + 1;
+
+ int check = (TreeNode.bottomUpTree(0,stretchDepth)).itemCheck();
+ System.out.println("stretch tree of depth "+stretchDepth+"\t check: " + check);
+
+ TreeNode longLivedTree = TreeNode.bottomUpTree(0,maxDepth);
+
+ for (int depth=minDepth; depth<=maxDepth; depth+=2){
+ int iterations = 1 << (maxDepth - depth + minDepth);
+ check = 0;
+
+ for (int i=1; i<=iterations; i++){
+ check += (TreeNode.bottomUpTree(i,depth)).itemCheck();
+ check += (TreeNode.bottomUpTree(-i,depth)).itemCheck();
+ }
+ System.out.println((iterations*2) + "\t trees of depth " + depth + "\t check: " + check);
+ }
+ System.out.println("long lived tree of depth " + maxDepth + "\t check: "+ longLivedTree.itemCheck());
+ }
+
+
+ private static class TreeNode
+ {
+ private TreeNode left, right;
+ private int item;
+
+ TreeNode(int item){
+ this.item = item;
+ }
+
+ private static TreeNode bottomUpTree(int item, int depth){
+ if (depth>0){
+ return new TreeNode(
+ bottomUpTree(2*item-1, depth-1)
+ , bottomUpTree(2*item, depth-1)
+ , item
+ );
+ }
+ else {
+ return new TreeNode(item);
+ }
+ }
+
+ TreeNode(TreeNode left, TreeNode right, int item){
+ this.left = left;
+ this.right = right;
+ this.item = item;
+ }
+
+ private int itemCheck(){
+ // if necessary deallocate here
+ if (left==null) return item;
+ else return item + left.itemCheck() - right.itemCheck();
+ }
+ }
}
View
246 benchmark/bench/chameneos.java
@@ -8,126 +8,126 @@
public class chameneos {
- private MeetingPlace mp;
-
- public static final Colour[] COLOURS = { Colour.BLUE, Colour.RED, Colour.YELLOW, Colour.BLUE };
-
- private Creature[] creatures = new Creature[COLOURS.length];
-
- public enum Colour {
- RED, BLUE, YELLOW, FADED
- }
-
- public class Creature extends Thread {
-
- private MeetingPlace mp;
- private Colour colour;
- private int met = 0;
- private Colour other;
-
- public Creature(Colour c, MeetingPlace mp) {
- this.colour = c;
- this.mp = mp;
- }
-
- public void run() {
- try {
- while (colour != Colour.FADED) {
- mp.meet(this);
- if (other == Colour.FADED)
- colour = Colour.FADED;
- else {
- met++;
- colour = complement(other);
- }
- }
- } catch (InterruptedException e) {
- // Let the thread exit.
- }
- }
-
- private Colour complement(Colour other) {
- if (colour == other)
- return colour;
- switch (colour) {
- case BLUE:
- return other == Colour.RED ? Colour.YELLOW : Colour.RED;
- case RED:
- return other == Colour.BLUE ? Colour.YELLOW : Colour.BLUE;
- case YELLOW:
- return other == Colour.BLUE ? Colour.RED : Colour.BLUE;
- default:
- return colour;
- }
- }
-
- public int getCreaturesMet() {
- return met;
- }
-
- public Colour getColour() {
- return colour;
- }
-
- public void setOther(Colour other) throws InterruptedException {
- this.other = other;
- }
- }
-
- public class MeetingPlace {
-
- int n;
-
- public MeetingPlace(int n) {
- this.n = n;
- }
-
- Creature other = null;
- public void meet(Creature c) throws InterruptedException {
-
- synchronized (this) {
- if (n > 0) {
- if (other == null) {
- other = c;
- this.wait();
- } else {
- other.setOther(c.getColour());
- c.setOther(other.getColour());
- other = null;
- n--;
- this.notify();
- }
- } else {
- c.setOther(Colour.FADED);
- }
- }
- }
- }
-
- public chameneos(int n) throws InterruptedException {
- int meetings = 0;
- mp = new MeetingPlace(n);
-
- for (int i = 0; i < COLOURS.length; i++) {
- creatures[i] = new Creature(COLOURS[i], mp);
- creatures[i].start();
- }
-
- // wait for all threads to complete
- for (int i = 0; i < COLOURS.length; i++)
- creatures[i].join();
-
- // sum all the meetings
- for (int i = 0; i < COLOURS.length; i++) {
- meetings += creatures[i].getCreaturesMet();
- }
-
- System.out.println(meetings);
- }
-
- public static void main(String[] args) throws Exception {
- if (args.length < 1)
- throw new IllegalArgumentException();
- new chameneos(Integer.parseInt(args[0]));
- }
-}
+ private MeetingPlace mp;
+
+ public static final Colour[] COLOURS = { Colour.BLUE, Colour.RED, Colour.YELLOW, Colour.BLUE };
+
+ private Creature[] creatures = new Creature[COLOURS.length];
+
+ public enum Colour {
+ RED, BLUE, YELLOW, FADED
+ }
+
+ public class Creature extends Thread {
+
+ private MeetingPlace mp;
+ private Colour colour;
+ private int met = 0;
+ private Colour other;
+
+ public Creature(Colour c, MeetingPlace mp) {
+ this.colour = c;
+ this.mp = mp;
+ }
+
+ public void run() {
+ try {
+ while (colour != Colour.FADED) {
+ mp.meet(this);
+ if (other == Colour.FADED)
+ colour = Colour.FADED;
+ else {
+ met++;
+ colour = complement(other);
+ }
+ }
+ } catch (InterruptedException e) {
+ // Let the thread exit.
+ }
+ }
+
+ private Colour complement(Colour other) {
+ if (colour == other)
+ return colour;
+ switch (colour) {
+ case BLUE:
+ return other == Colour.RED ? Colour.YELLOW : Colour.RED;
+ case RED:
+ return other == Colour.BLUE ? Colour.YELLOW : Colour.BLUE;
+ case YELLOW:
+ return other == Colour.BLUE ? Colour.RED : Colour.BLUE;
+ default:
+ return colour;
+ }
+ }
+
+ public int getCreaturesMet() {
+ return met;
+ }
+
+ public Colour getColour() {
+ return colour;
+ }
+
+ public void setOther(Colour other) throws InterruptedException {
+ this.other = other;
+ }
+ }
+
+ public class MeetingPlace {
+
+ int n;
+
+ public MeetingPlace(int n) {
+ this.n = n;
+ }
+
+ Creature other = null;
+ public void meet(Creature c) throws InterruptedException {
+
+ synchronized (this) {
+ if (n > 0) {
+ if (other == null) {
+ other = c;
+ this.wait();
+ } else {
+ other.setOther(c.getColour());
+ c.setOther(other.getColour());
+ other = null;
+ n--;
+ this.notify();
+ }
+ } else {
+ c.setOther(Colour.FADED);
+ }
+ }
+ }
+ }
+
+ public chameneos(int n) throws InterruptedException {
+ int meetings = 0;
+ mp = new MeetingPlace(n);
+
+ for (int i = 0; i < COLOURS.length; i++) {
+ creatures[i] = new Creature(COLOURS[i], mp);
+ creatures[i].start();
+ }
+
+ // wait for all threads to complete
+ for (int i = 0; i < COLOURS.length; i++)
+ creatures[i].join();
+
+ // sum all the meetings
+ for (int i = 0; i < COLOURS.length; i++) {
+ meetings += creatures[i].getCreaturesMet();
+ }
+
+ System.out.println(meetings);
+ }
+
+ public static void main(String[] args) throws Exception {
+ if (args.length < 1)
+ throw new IllegalArgumentException();
+ new chameneos(Integer.parseInt(args[0]));
+ }
+}
View
98 benchmark/bench/echo.java
@@ -7,13 +7,13 @@
public class echo {
public static void main(String[] args) throws Exception {
- int iIterations = 1;
- try {
- iIterations = Integer.parseInt(args[0]);
- } catch(Exception e) { }
+ int iIterations = 1;
+ try {
+ iIterations = Integer.parseInt(args[0]);
+ } catch(Exception e) { }
- EchoServer esServer = new EchoServer(0);
- new EchoClient(InetAddress.getLocalHost(), esServer.getPort(), iIterations);
+ EchoServer esServer = new EchoServer(0);
+ new EchoClient(InetAddress.getLocalHost(), esServer.getPort(), iIterations);
}
}
@@ -24,35 +24,35 @@ public static void main(String[] args) throws Exception {
private final int iIterations;
public EchoClient(InetAddress inetaServer, int iPort, int iIterations) {
- this.inetaServer = inetaServer;
- this.iPort = iPort;
- this.iIterations = iIterations;
- start();
+ this.inetaServer = inetaServer;
+ this.iPort = iPort;
+ this.iIterations = iIterations;
+ start();
}
public void run() {
- Socket socketFromServer = null;
- try {
- socketFromServer = new Socket(inetaServer, iPort);
- BufferedReader in = new BufferedReader(new InputStreamReader(socketFromServer.getInputStream()));
- OutputStream out = socketFromServer.getOutputStream();
+ Socket socketFromServer = null;
+ try {
+ socketFromServer = new Socket(inetaServer, iPort);
+ BufferedReader in = new BufferedReader(new InputStreamReader(socketFromServer.getInputStream()));
+ OutputStream out = socketFromServer.getOutputStream();
- byte[] bytesOut = GREETING.getBytes();
- String strIn = GREETING.trim();
- for(int i = 0; i < iIterations; ++i) {
- out.write(bytesOut);
- out.flush();
- String strRead = in.readLine();
- if(!strRead.equals(strIn))
- throw new RuntimeException("client: \"" + strIn + "\" ne \"" + strRead + "\"");
- }
- } catch(Exception e) {
- e.printStackTrace();
- }
+ byte[] bytesOut = GREETING.getBytes();
+ String strIn = GREETING.trim();
+ for(int i = 0; i < iIterations; ++i) {
+ out.write(bytesOut);
+ out.flush();
+ String strRead = in.readLine();
+ if(!strRead.equals(strIn))
+ throw new RuntimeException("client: \"" + strIn + "\" ne \"" + strRead + "\"");
+ }
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
- try {
- socketFromServer.close();
- } catch(Exception e) { }
+ try {
+ socketFromServer.close();
+ } catch(Exception e) { }
}
}
@@ -62,30 +62,30 @@ public void run() {
private final int iPort;
public EchoServer(int iPort) throws IOException {
- ssAccepting = new ServerSocket(iPort);
- this.iPort = ssAccepting.getLocalPort();
- start();
+ ssAccepting = new ServerSocket(iPort);
+ this.iPort = ssAccepting.getLocalPort();
+ start();
}
public final int getPort() {
- return iPort;
+ return iPort;
}
public void run() {
- byte bytesIn[] = new byte[BUFFER_SIZE];
- try {
- Socket socketClient = ssAccepting.accept();
- InputStream in = socketClient.getInputStream();
- OutputStream out = socketClient.getOutputStream();
- int iLength, iCount = 0;
- while ((iLength = in.read(bytesIn)) != -1) {
- out.write(bytesIn, 0, iLength);
- out.flush();
- iCount += iLength;
- }
- System.out.println("server processed " + iCount + " bytes");
- } catch (Exception e) {
- e.printStackTrace();
- }
+ byte bytesIn[] = new byte[BUFFER_SIZE];
+ try {
+ Socket socketClient = ssAccepting.accept();
+ InputStream in = socketClient.getInputStream();
+ OutputStream out = socketClient.getOutputStream();
+ int iLength, iCount = 0;
+ while ((iLength = in.read(bytesIn)) != -1) {
+ out.write(bytesIn, 0, iLength);
+ out.flush();
+ iCount += iLength;
+ }
+ System.out.println("server processed " + iCount + " bytes");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
View
58 benchmark/bench/except.java
@@ -9,20 +9,20 @@
class Lo_Exception extends Exception {
int num = 0;
public Lo_Exception(int num) {
- this.num = num;
+ this.num = num;
}
public String toString() {
- return "Lo_Exception, num = " + this.num;
+ return "Lo_Exception, num = " + this.num;
}
}
class Hi_Exception extends Exception {
int num = 0;
public Hi_Exception(int num) {
- this.num = num;
+ this.num = num;
}
public String toString() {
- return "Hi_Exception, num = " + this.num;
+ return "Hi_Exception, num = " + this.num;
}
}
@@ -31,43 +31,43 @@ public String toString() {
static int Hi = 0;
public static void main(String args[]) throws IOException {
- int n = Integer.parseInt(args[0]);
+ int n = Integer.parseInt(args[0]);
- for (int i=0; i<n; i++) {
- some_function(i);
- }
- System.out.println("Exceptions: HI=" + Hi + " / LO=" + Lo);
+ for (int i=0; i<n; i++) {
+ some_function(i);
+ }
+ System.out.println("Exceptions: HI=" + Hi + " / LO=" + Lo);
}
public static void some_function(int n) {
- try {
- hi_function(n);
- } catch (Exception e) {
- System.out.println("We shouldn't get here: " + e);
- }
+ try {
+ hi_function(n);
+ } catch (Exception e) {
+ System.out.println("We shouldn't get here: " + e);
+ }
}
public static void hi_function(int n) throws Hi_Exception, Lo_Exception {
- try {
- lo_function(n);
- } catch (Hi_Exception e) {
- Hi++;
- }
+ try {
+ lo_function(n);
+ } catch (Hi_Exception e) {
+ Hi++;
+ }
}
public static void lo_function(int n) throws Hi_Exception, Lo_Exception {
- try {
- blowup(n);
- } catch (Lo_Exception e) {
- Lo++;
- }
+ try {
+ blowup(n);
+ } catch (Lo_Exception e) {
+ Lo++;
+ }
}
public static void blowup(int n) throws Hi_Exception, Lo_Exception {
- if ((n % 2) == 0) {
- throw new Lo_Exception(n);
- } else {
- throw new Hi_Exception(n);
- }
+ if ((n % 2) == 0) {
+ throw new Lo_Exception(n);
+ } else {
+ throw new Hi_Exception(n);
+ }
}
}
View
13 benchmark/bench/fannkuch.groovy
@@ -1,15 +1,16 @@
-/* The Computer Language Benchmarks Game
- http://shootout.alioth.debian.org/
- contributed by Brian Schlining
-*/
+/*
+ * The Computer Language Benchmarks Game
+ * http://shootout.alioth.debian.org/
+ *
+ * contributed by Brian Schlining
+ */
def n = 7
if (args.length > 0) {
n = Integer.parseInt(args[0])
}
println("Pfannkuchen(" + n + ") = " + fannkuch(n))
-
def fannkuch(int n) {
int check = 0
int[] perm = new int[n]
@@ -36,7 +37,7 @@ def fannkuch(int n) {
while (r != 1) {
count[r - 1] = r
- r--
+ r--
}
if (!(perm1[0] == 0 || perm1[m] == m)) {
for (i in 0..<n) {
View
42 benchmark/bench/fannkuchredux.java
@@ -11,14 +11,14 @@
public final class fannkuchredux implements Runnable
{
private static final int NCHUNKS = 150;
- private static int CHUNKSZ;
- private static int NTASKS;
+ private static int CHUNKSZ;
+ private static int NTASKS;
private static int n;
private static int[] Fact;
private static int[] maxFlips;
private static int[] chkSums;
private static AtomicInteger taskId;
-
+
int[] p, pp, count;
void print()
@@ -52,8 +52,8 @@ boolean nextPermutation()
int first = p[1];
p[1] = p[0];
p[0] = first;
-
- int i=1;
+
+ int i=1;
while ( ++count[i] > i ) {
count[i++] = 0;
int next = p[0] = p[1];
@@ -69,7 +69,7 @@ boolean nextPermutation()
int countFlips()
{
int flips = 1;
- int first = p[0];
+ int first = p[0];
if ( p[first] != 0 ) {
System.arraycopy( p, 0, pp, 0, pp.length );
do {
@@ -84,15 +84,15 @@ int countFlips()
first = t;
} while ( pp[first] != 0 );
}
- return flips;
+ return flips;
}
void runTask( int task )
{
int idxMin = task*CHUNKSZ;
int idxMax = Math.min( Fact[n], idxMin+CHUNKSZ );
- firstPermutation( idxMin );
+ firstPermutation( idxMin );
int maxflips = 1;
int chksum = 0;
@@ -101,28 +101,28 @@ void runTask( int task )
if ( p[0] != 0 ) {
int flips = countFlips();
maxflips = Math.max( maxflips, flips );
- chksum += i%2 ==0 ? flips : -flips;
+ chksum += i%2 ==0 ? flips : -flips;
}
- if ( ++i == idxMax ) {
- break;
- }
+ if ( ++i == idxMax ) {
+ break;
+ }
nextPermutation();
}
- maxFlips[task] = maxflips;
- chkSums[task] = chksum;
+ maxFlips[task] = maxflips;
+ chkSums[task] = chksum;
}
public void run()
{
p = new int[n];
pp = new int[n];
- count = new int[n];
+ count = new int[n];
int task;
while ( ( task = taskId.getAndIncrement() ) < NTASKS ) {
- runTask( task );
+ runTask( task );
}
}
@@ -132,7 +132,7 @@ static void printResult( int n, int res, int chk )
}
public static void main( String[] args )
- {
+ {
n = args.length > 0 ? Integer.parseInt( args[0] ) : 12;
if ( n < 0 || n > 12 ) { // 13! won't fit into int
printResult( n, -1, -1 );
@@ -148,9 +148,9 @@ public static void main( String[] args )
for ( int i=1; i<Fact.length; ++i ) {
Fact[i] = Fact[i-1] * i;
}
-
+
CHUNKSZ = (Fact[n] + NCHUNKS - 1) / NCHUNKS;
- NTASKS = (Fact[n] + CHUNKSZ - 1) / CHUNKSZ;
+ NTASKS = (Fact[n] + CHUNKSZ - 1) / CHUNKSZ;
maxFlips = new int[NTASKS];
chkSums = new int[NTASKS];
taskId = new AtomicInteger(0);
@@ -167,7 +167,7 @@ public static void main( String[] args )
}
catch ( InterruptedException e ) {}
}
-
+
int res = 0;
for ( int v : maxFlips ) {
res = Math.max( res, v );
@@ -176,7 +176,7 @@ public static void main( String[] args )
for ( int v : chkSums ) {
chk += v;
}
-
+
printResult( n, res, chk );
}
}
View
8 benchmark/bench/fibo.java
@@ -3,11 +3,11 @@
public class fibo {
public static void main(String args[]) {
- int N = Integer.parseInt(args[0]);
- System.out.println(fib(N));
+ int N = Integer.parseInt(args[0]);
+ System.out.println(fib(N));
}
public static int fib(int n) {
- if (n < 2) return(1);
- return( fib(n-2) + fib(n-1) );
+ if (n < 2) return(1);
+ return( fib(n-2) + fib(n-1) );
}
}
View
36 benchmark/bench/hash.java
@@ -13,26 +13,26 @@
public class hash {
public static void main(String args[]) throws IOException {
- int n = Integer.parseInt(args[0]);
- int i, c;
- String s = "";
- Integer ii;
- // the original program used:
- // Hashtable ht = new Hashtable();
- // John Olsson points out that Hashtable is for synchronized access
- // and we should use instead:
- HashMap ht = new HashMap();
+ int n = Integer.parseInt(args[0]);
+ int i, c;
+ String s = "";
+ Integer ii;
+ // the original program used:
+ // Hashtable ht = new Hashtable();
+ // John Olsson points out that Hashtable is for synchronized access
+ // and we should use instead:
+ HashMap ht = new HashMap();
- c = 0;
- for (i = 1; i <= n; i++)
- ht.put(Integer.toString(i, 16), new Integer(i));
- for (i = 1; i <= n; i++)
- // The original code converted to decimal string this way:
- // if (ht.containsKey(i+""))
- if (ht.containsKey(Integer.toString(i, 10)))
- c++;
+ c = 0;
+ for (i = 1; i <= n; i++)
+ ht.put(Integer.toString(i, 16), new Integer(i));
+ for (i = 1; i <= n; i++)
+ // The original code converted to decimal string this way:
+ // if (ht.containsKey(i+""))
+ if (ht.containsKey(Integer.toString(i, 10)))
+ c++;
- System.out.println(c);
+ System.out.println(c);
}
}
View
42 benchmark/bench/hash2.java
@@ -10,28 +10,28 @@
public class hash2 {
public static void main(String args[]) {
- int n = Integer.parseInt(args[0]);
- HashMap hash1 = new HashMap(10000);
- HashMap hash2 = new HashMap(n);
+ int n = Integer.parseInt(args[0]);
+ HashMap hash1 = new HashMap(10000);
+ HashMap hash2 = new HashMap(n);
- for(int i = 0; i < 10000; i++)
- hash1.put("foo_" + Integer.toString(i, 10), new Val(i));
- for(int i = 0; i < n; i++) {
- Iterator it = hash1.entrySet().iterator();
- while(it.hasNext()) {
- Map.Entry h1 = (Map.Entry)it.next();
- String key = (String)h1.getKey();
- int v1 = ((Val)h1.getValue()).val;
- if (hash2.containsKey(key))
- ((Val)hash2.get(key)).val += v1;
- else
- hash2.put(key, new Val(v1));
- }
- }
+ for(int i = 0; i < 10000; i++)
+ hash1.put("foo_" + Integer.toString(i, 10), new Val(i));
+ for(int i = 0; i < n; i++) {
+ Iterator it = hash1.entrySet().iterator();
+ while(it.hasNext()) {
+ Map.Entry h1 = (Map.Entry)it.next();
+ String key = (String)h1.getKey();
+ int v1 = ((Val)h1.getValue()).val;
+ if (hash2.containsKey(key))
+ ((Val)hash2.get(key)).val += v1;
+ else
+ hash2.put(key, new Val(v1));
+ }
+ }
- System.out.print(((Val)hash1.get("foo_1")).val + " " +
- ((Val)hash1.get("foo_9999")).val + " " +
- ((Val)hash2.get("foo_1")).val + " " +
- ((Val)hash2.get("foo_9999")).val + "\n");
+ System.out.print(((Val)hash1.get("foo_1")).val + " " +
+ ((Val)hash1.get("foo_9999")).val + " " +
+ ((Val)hash2.get("foo_1")).val + " " +
+ ((Val)hash2.get("foo_9999")).val + "\n");
}
}
View
86 benchmark/bench/heapsort.groovy
@@ -1,49 +1,52 @@
/*
- The Computer Language Shootout
- http://shootout.alioth.debian.org/
+ * The Computer Language Shootout
+ * http://shootout.alioth.debian.org/
+ *
+ * contributed by Jochen Hinrichsen
+ */
+public static final long IM = 139968
+public static final long IA = 3877
+public static final long IC = 29573
- contributed by Jochen Hinrichsen
-*/
- public static final long IM = 139968
- public static final long IA = 3877
- public static final long IC = 29573
+public static long last = 42
- public static long last = 42
- def gen_random(double max) {
- max * (last = (last * IA + IC) % IM) / IM
- }
+def gen_random(double max) {
+ max * (last = (last * IA + IC) % IM) / IM
+}
- def heapsort(int n, double[] ra) {
- int l, j, ir, i
- double rra
+def heapsort(int n, double[] ra) {
+ int l, j, ir, i
+ double rra
- l = (n >> 1) + 1
- ir = n
- while (true) {
- if (l > 1) {
- rra = ra[--l]
- } else {
- rra = ra[ir]
- ra[ir] = ra[1]
- if (--ir == 1) {
- ra[1] = rra
- return
- }
- }
- i = l
- j = l << 1
- while (j <= ir) {
- if (j < ir && ra[j] < ra[j+1]) { ++j }
- if (rra < ra[j]) {
- ra[i] = ra[j]
- j += (i = j)
- } else {
- j = ir + 1
- }
- }
- ra[i] = rra
- }
+ l = (n >> 1) + 1
+ ir = n
+ while (true) {
+ if (l > 1) {
+ rra = ra[--l]
+ } else {
+ rra = ra[ir]
+ ra[ir] = ra[1]
+ if (--ir == 1) {
+ ra[1] = rra
+ return
+ }
+ }
+ i = l
+ j = l << 1
+ while (j <= ir) {
+ if (j < ir && ra[j] < ra[j+1]) {
+ ++j
+ }
+ if (rra < ra[j]) {
+ ra[i] = ra[j]
+ j += (i = j)
+ } else {
+ j = ir + 1
+ }
+ }
+ ra[i] = rra
}
+}
def N = (args.length == 0) ? 1000 : args[0].toInteger()
def nf = java.text.NumberFormat.getInstance()
@@ -56,6 +59,3 @@ for (i in 0..<N) {
}
heapsort(N, ary)
println nf.format(ary[N])
-
-// EOF
-
View
80 benchmark/bench/heapsort.java
@@ -11,53 +11,53 @@
public static final long IC = 29573;
public static void main(String args[]) {
- int N = Integer.parseInt(args[0]);
- NumberFormat nf = NumberFormat.getInstance();
- nf.setMaximumFractionDigits(10);
- nf.setMinimumFractionDigits(10);
- nf.setGroupingUsed(false);
- double []ary = (double[])Array.newInstance(double.class, N+1);
- for (int i=1; i<=N; i++) {
- ary[i] = gen_random(1);
- }
- heapsort(N, ary);
- System.out.print(nf.format(ary[N]) + "\n");
+ int N = Integer.parseInt(args[0]);
+ NumberFormat nf = NumberFormat.getInstance();
+ nf.setMaximumFractionDigits(10);
+ nf.setMinimumFractionDigits(10);
+ nf.setGroupingUsed(false);
+ double []ary = (double[])Array.newInstance(double.class, N+1);
+ for (int i=1; i<=N; i++) {
+ ary[i] = gen_random(1);
+ }
+ heapsort(N, ary);
+ System.out.print(nf.format(ary[N]) + "\n");
}
public static long last = 42;
public static double gen_random(double max) {
- return( max * (last = (last * IA + IC) % IM) / IM );
+ return( max * (last = (last * IA + IC) % IM) / IM );
}
public static void heapsort(int n, double ra[]) {
- int l, j, ir, i;
- double rra;
+ int l, j, ir, i;
+ double rra;
- l = (n >> 1) + 1;
- ir = n;
- for (;;) {
- if (l > 1) {
- rra = ra[--l];
- } else {
- rra = ra[ir];
- ra[ir] = ra[1];
- if (--ir == 1) {
- ra[1] = rra;
- return;
- }
- }
- i = l;
- j = l << 1;
- while (j <= ir) {
- if (j < ir && ra[j] < ra[j+1]) { ++j; }
- if (rra < ra[j]) {
- ra[i] = ra[j];
- j += (i = j);
- } else {
- j = ir + 1;
- }
- }
- ra[i] = rra;
- }
+ l = (n >> 1) + 1;
+ ir = n;
+ for (;;) {
+ if (l > 1) {
+ rra = ra[--l];
+ } else {
+ rra = ra[ir];
+ ra[ir] = ra[1];
+ if (--ir == 1) {
+ ra[1] = rra;
+ return;
+ }
+ }
+ i = l;
+ j = l << 1;
+ while (j <= ir) {
+ if (j < ir && ra[j] < ra[j+1]) { ++j; }
+ if (rra < ra[j]) {
+ ra[i] = ra[j];
+ j += (i = j);
+ } else {
+ j = ir + 1;
+ }
+ }
+ ra[i] = rra;
+ }
}
}
View
15 benchmark/bench/hello.groovy
@@ -1,11 +1,8 @@
/*
- The Computer Language Shootout
- http://shootout.alioth.debian.org/
-
- contributed by Jochen Hinrichsen
-*/
-
-println "hello world"
-
-// EOF
+ * The Computer Language Shootout
+ * http://shootout.alioth.debian.org/
+ *
+ * contributed by Jochen Hinrichsen
+ */
+println 'hello world'
View
2 benchmark/bench/hello.java
@@ -3,6 +3,6 @@
public class hello {
public static void main(String args[]) {
- System.out.print("hello world\n");
+ System.out.print("hello world\n");
}
}
View
194 benchmark/bench/knucleotide.java
@@ -1,6 +1,6 @@
/* The Computer Language Benchmarks Game
http://shootout.alioth.debian.org/
-
+
contributed by James McIlree
*/
@@ -11,115 +11,115 @@
public class knucleotide {
String sequence;
int count = 1;
-
+
knucleotide(String sequence) {
- this.sequence = sequence;
+ this.sequence = sequence;
}
static ArrayList<Callable< Map<String, knucleotide> > > createFragmentTasks(final String sequence, int[] fragmentLengths) {
- ArrayList<Callable<Map<String, knucleotide>>> tasks = new ArrayList<Callable<Map<String, knucleotide>>>();
- for (int fragmentLength : fragmentLengths) {
- for (int index=0; index<fragmentLength; index++) {
- final int offset = index;
- final int finalFragmentLength = fragmentLength;
- tasks.add(new Callable<Map<String, knucleotide>>() {
- public Map<String, knucleotide> call() {
- return createFragmentMap(sequence, offset, finalFragmentLength);
- }
- });
- }
- }
- return tasks;
+ ArrayList<Callable<Map<String, knucleotide>>> tasks = new ArrayList<Callable<Map<String, knucleotide>>>();
+ for (int fragmentLength : fragmentLengths) {
+ for (int index=0; index<fragmentLength; index++) {
+ final int offset = index;
+ final int finalFragmentLength = fragmentLength;
+ tasks.add(new Callable<Map<String, knucleotide>>() {
+ public Map<String, knucleotide> call() {
+ return createFragmentMap(sequence, offset, finalFragmentLength);
+ }
+ });
+ }
+ }
+ return tasks;
}
-
+
static Map<String, knucleotide> createFragmentMap(String sequence, int offset, int fragmentLength) {
- HashMap<String, knucleotide> map = new HashMap<String, knucleotide>();
- int lastIndex = sequence.length() - fragmentLength + 1;
- for (int index=offset; index<lastIndex; index+=fragmentLength) {
- String temp = sequence.substring(index, index + fragmentLength);
- knucleotide fragment = (knucleotide)map.get(temp);
- if (fragment != null)
- fragment.count++;
- else
- map.put(temp, new knucleotide(temp));
- }
-
- return map;
+ HashMap<String, knucleotide> map = new HashMap<String, knucleotide>();
+ int lastIndex = sequence.length() - fragmentLength + 1;
+ for (int index=offset; index<lastIndex; index+=fragmentLength) {
+ String temp = sequence.substring(index, index + fragmentLength);
+ knucleotide fragment = (knucleotide)map.get(temp);
+ if (fragment != null)
+ fragment.count++;
+ else
+ map.put(temp, new knucleotide(temp));
+ }
+
+ return map;
}
-
+
// Destructive!
static Map<String, knucleotide> sumTwoMaps(Map<String, knucleotide> map1, Map<String, knucleotide> map2) {
- for (Map.Entry<String, knucleotide> entry : map2.entrySet()) {
- knucleotide sum = (knucleotide)map1.get(entry.getKey());
- if (sum != null)
- sum.count += entry.getValue().count;
- else
- map1.put(entry.getKey(), entry.getValue());
- }
- return map1;
+ for (Map.Entry<String, knucleotide> entry : map2.entrySet()) {
+ knucleotide sum = (knucleotide)map1.get(entry.getKey());
+ if (sum != null)
+ sum.count += entry.getValue().count;
+ else
+ map1.put(entry.getKey(), entry.getValue());
+ }
+ return map1;
}
-
+
static String writeFrequencies(Map<String, knucleotide> frequencies) {
- ArrayList<knucleotide> list = new ArrayList<knucleotide>(frequencies.size());
- int sum = 0;
- for (knucleotide fragment : frequencies.values()) {
- list.add(fragment);
- sum += fragment.count;
- }
-
- Collections.sort(list, new Comparator<knucleotide>() {
- public int compare(knucleotide o1, knucleotide o2) {
- int c = o2.count - o1.count;
- if (c == 0) {
- c = o1.sequence.compareTo(o2.sequence);
- }
- return c;
- }
- });
-
- StringBuilder sb = new StringBuilder();
- for (knucleotide k : list)
- sb.append(String.format("%s %.3f\n", k.sequence.toUpperCase(), (float)(k.count) * 100.0f / (double)sum));
-
- return sb.toString();
+ ArrayList<knucleotide> list = new ArrayList<knucleotide>(frequencies.size());
+ int sum = 0;
+ for (knucleotide fragment : frequencies.values()) {
+ list.add(fragment);
+ sum += fragment.count;
+ }
+
+ Collections.sort(list, new Comparator<knucleotide>() {
+ public int compare(knucleotide o1, knucleotide o2) {
+ int c = o2.count - o1.count;
+ if (c == 0) {
+ c = o1.sequence.compareTo(o2.sequence);
+ }
+ return c;
+ }
+ });
+
+ StringBuilder sb = new StringBuilder();
+ for (knucleotide k : list)
+ sb.append(String.format("%s %.3f\n", k.sequence.toUpperCase(), (float)(k.count) * 100.0f / (double)sum));
+
+ return sb.toString();
}
-
+
static String writeCount(List<Future<Map<String, knucleotide>>> futures, String nucleotideFragment) throws Exception {
- int count = 0;
- for (Future<Map<String, knucleotide>> future : futures) {
- knucleotide temp = future.get().get(nucleotideFragment);
- if (temp != null) count += temp.count;
- }
-
- return count + "\t" + nucleotideFragment.toUpperCase();
+ int count = 0;
+ for (Future<Map<String, knucleotide>> future : futures) {
+ knucleotide temp = future.get().get(nucleotideFragment);
+ if (temp != null) count += temp.count;
+ }
+
+ return count + "\t" + nucleotideFragment.toUpperCase();
}
-
- public static void main (String[] args) throws Exception {
- String line;
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- while ((line = in.readLine()) != null) {
- if (line.startsWith(">THREE")) break;
- }
-
- StringBuilder sbuilder = new StringBuilder();
- while ((line = in.readLine()) != null) {
- sbuilder.append(line);
- }
-
- ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
- int[] fragmentLengths = { 1, 2, 3, 4, 6, 12, 18 };
- List<Future<Map<String, knucleotide>>> futures = pool.invokeAll(createFragmentTasks(sbuilder.toString(), fragmentLengths));
- pool.shutdown();
-
- // Print the length 1 & 2 counts. We know the offsets of the tasks, so we can cheat.
- System.out.println(writeFrequencies(futures.get(0).get()));
- System.out.println(writeFrequencies(sumTwoMaps(futures.get(1).get(), futures.get(2).get())));
-
- System.out.println(writeCount(futures, "ggt"));
- System.out.println(writeCount(futures, "ggta"));
- System.out.println(writeCount(futures, "ggtatt"));
- System.out.println(writeCount(futures, "ggtattttaatt"));
- System.out.println(writeCount(futures, "ggtattttaatttatagt"));
+
+ public static void main (String[] args) throws Exception {
+ String line;
+ BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
+ while ((line = in.readLine()) != null) {
+ if (line.startsWith(">THREE")) break;
+ }
+
+ StringBuilder sbuilder = new StringBuilder();
+ while ((line = in.readLine()) != null) {
+ sbuilder.append(line);
+ }
+
+ ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
+ int[] fragmentLengths = { 1, 2, 3, 4, 6, 12, 18 };
+ List<Future<Map<String, knucleotide>>> futures = pool.invokeAll(createFragmentTasks(sbuilder.toString(), fragmentLengths));
+ pool.shutdown();
+
+ // Print the length 1 & 2 counts. We know the offsets of the tasks, so we can cheat.
+ System.out.println(writeFrequencies(futures.get(0).get()));
+ System.out.println(writeFrequencies(sumTwoMaps(futures.get(1).get(), futures.get(2).get())));
+
+ System.out.println(writeCount(futures, "ggt"));
+ System.out.println(writeCount(futures, "ggta"));
+ System.out.println(writeCount(futures, "ggtatt"));
+ System.out.println(writeCount(futures, "ggtattttaatt"));
+ System.out.println(writeCount(futures, "ggtattttaatttatagt"));
}
-
+
}
View
94 benchmark/bench/lists.java
@@ -9,54 +9,54 @@
static int SIZE = 10000;
public static void main(String args[]) {
- int n = Integer.parseInt(args[0]);
- int result = 0;
- for (int i = 0; i < n; i++) {
- result = test_lists();
- }
- System.out.println(result);
+ int n = Integer.parseInt(args[0]);
+ int result = 0;
+ for (int i = 0; i < n; i++) {
+ result = test_lists();
+ }
+ System.out.println(result);
}
public static int test_lists() {
- int result = 0;
- // create a list of integers (Li1) from 1 to SIZE
- LinkedList Li1 = new LinkedList();
- for (int i = 1; i < SIZE+1; i++) {
- Li1.addLast(new Integer(i));
- }
- // copy the list to Li2 (not by individual items)
- LinkedList Li2 = new LinkedList(Li1);
- LinkedList Li3 = new LinkedList();
- // remove each individual item from left side of Li2 and
- // append to right side of Li3 (preserving order)
- while (! Li2.isEmpty()) {
- Li3.addLast(Li2.removeFirst());
- }
- // Li2 must now be empty
- // remove each individual item from right side of Li3 and
- // append to right side of Li2 (reversing list)
- while (! Li3.isEmpty()) {
- Li2.addLast(Li3.removeLast());
- }
- // Li3 must now be empty
- // reverse Li1
- LinkedList tmp = new LinkedList();
- while (! Li1.isEmpty()) {
- tmp.addFirst(Li1.removeFirst());
- }
- Li1 = tmp;
- // check that first item is now SIZE
- if (((Integer)Li1.getFirst()).intValue() != SIZE) {
- System.err.println("first item of Li1 != SIZE");
- return(0);
- }
- // compare Li1 and Li2 for equality
- if (! Li1.equals(Li2)) {
- System.err.println("Li1 and Li2 differ");
- System.err.println("Li1:" + Li1);
- System.err.println("Li2:" + Li2);
- return(0);
- }
- // return the length of the list
- return(Li1.size());
+ int result = 0;
+ // create a list of integers (Li1) from 1 to SIZE
+ LinkedList Li1 = new LinkedList();
+ for (int i = 1; i < SIZE+1; i++) {
+ Li1.addLast(new Integer(i));
+ }
+ // copy the list to Li2 (not by individual items)
+ LinkedList Li2 = new LinkedList(Li1);
+ LinkedList Li3 = new LinkedList();
+ // remove each individual item from left side of Li2 and
+ // append to right side of Li3 (preserving order)
+ while (! Li2.isEmpty()) {
+ Li3.addLast(Li2.removeFirst());
+ }
+ // Li2 must now be empty
+ // remove each individual item from right side of Li3 and
+ // append to right side of Li2 (reversing list)
+ while (! Li3.isEmpty()) {
+ Li2.addLast(Li3.removeLast());
+ }
+ // Li3 must now be empty
+ // reverse Li1
+ LinkedList tmp = new LinkedList();
+ while (! Li1.isEmpty()) {
+ tmp.addFirst(Li1.removeFirst());
+ }
+ Li1 = tmp;
+ // check that first item is now SIZE
+ if (((Integer)Li1.getFirst()).intValue() != SIZE) {
+ System.err.println("first item of Li1 != SIZE");
+ return(0);
+ }
+ // compare Li1 and Li2 for equality
+ if (! Li1.equals(Li2)) {
+ System.err.println("Li1 and Li2 differ");
+ System.err.println("Li1:" + Li1);
+ System.err.println("Li2:" + Li2);
+ return(0);
+ }
+ // return the length of the list
+ return(Li1.size());
}
}
View
82 benchmark/bench/mandelbrot.groovy
@@ -1,55 +1,45 @@
/*
- The Computer Language Shootout
- http://shootout.alioth.debian.org/
-
- contributed by Jochen Hinrichsen
-*/
-
-double Cr, Ci, Tr, Ti, Zr=0, Zi=0, limit_sq = 4.0
-int res, i=0, x=0, y=0, pos=0, acc=1, iter = 50
+ * The Computer Language Shootout
+ * http://shootout.alioth.debian.org/
+ *
+ * contributed by Jochen Hinrichsen
+ */
+
+double Cr, Ci, Tr, Ti, Zr = 0, Zi = 0, limit_sq = 4.0
+int res, i = 0, x = 0, y = 0, pos = 0, acc = 1, iter = 50
res = (args.length >= 1) ? Integer.parseInt(args[0], 10) : 200
int max = (res * res) >>> 3
-def pbm_data = new byte[ max ]
-String pbm_header = new String("P4" + ((char) 012) + res + " " + res + ((char) 012))
+def pbm_data = new byte[max]
+String pbm_header = new String('P4' + ((char) 012) + res + ' ' + res + ((char) 012))
System.out.write(pbm_header.getBytes(), 0, pbm_header.length())
-// for ( ; pos < max; x%=res, Zr=Zi=i=0) {
while (pos < max) {
- Cr = (2*((double)x++)/res - 1.5);
- Ci=(2*((double)y)/res - 1)
-
- // for(acc<<=1; (acc&1)==0 && i++ < iter; acc |= Zr*Zr+Zi*Zi > limit_sq ? 1 : 0) {
- acc<<=1
- while (((acc&1)==0) && (i++ < iter)) {
- Tr = Zr*Zr - Zi*Zi + Cr
- Ti = 2*Zr*Zi + Ci
- Zr = Tr