<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Benchmarks</title><link>https://sourceforge.net/p/groovylab/wiki/Benchmarks/</link><description>Recent changes to Benchmarks</description><atom:link href="https://sourceforge.net/p/groovylab/wiki/Benchmarks/feed" rel="self"/><language>en</language><lastBuildDate>Wed, 22 Jan 2014 10:30:42 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/groovylab/wiki/Benchmarks/feed" rel="self" type="application/rss+xml"/><item><title>Benchmarks modified by Anonymous</title><link>https://sourceforge.net/p/groovylab/wiki/Benchmarks/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="introduction"&gt;Introduction&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;This page presents benchmarking code that can be executed in Glab. Also, we give our execution times, for comparison.&lt;/code&gt;&lt;/p&gt;
&lt;h1 id="binary-trees-static-compilation"&gt;Binary Trees - Static Compilation&lt;/h1&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;@groovy.transform.CompileStatic

== Binary Trees  - Groovy 1.8.2 ==
{{{

public class BinaryTrees {

private final static int minDepth = 4;

public static void main(String[] args){
        final long millis = System.currentTimeMillis();

        int n = 20;
if (args.length &amp;gt; 0) n = Integer.parseInt(args[0]);

int maxDepth = (minDepth + 2 &amp;gt; n) ? minDepth + 2 : n;
int stretchDepth = maxDepth + 1;

int check = (TreeNode.bottomUpTree(0,stretchDepth)).itemCheck();
System.out.println(&amp;quot;stretch tree of depth &amp;quot;+stretchDepth+&amp;quot;\t check: &amp;quot; + check);

TreeNode longLivedTree = TreeNode.bottomUpTree(0,maxDepth);

for (int depth=minDepth; depth&lt;span class="err"&gt;&amp;lt;&lt;/span&gt;=maxDepth; depth+=2){
int iterations = 1 &lt;span class="err"&gt;&amp;lt;&amp;lt;&lt;/span&gt; (maxDepth - depth + minDepth);
check = 0;

for (int i=1; i&lt;span class="err"&gt;&amp;lt;&lt;/span&gt;=iterations; i++){
check += (TreeNode.bottomUpTree(i,depth)).itemCheck();
check += (TreeNode.bottomUpTree(-i,depth)).itemCheck();
}
System.out.println((iterations*2) + &amp;quot;\t trees of depth &amp;quot; + depth + &amp;quot;\t check: &amp;quot; + check);
}
System.out.println(&amp;quot;long lived tree of depth &amp;quot; + maxDepth + &amp;quot;\t check: &amp;quot;+ longLivedTree.itemCheck());

        long total = System.currentTimeMillis() - millis;
System.out.println(&amp;quot;[Binary Trees-&amp;quot; + System.getProperty(&amp;quot;project.name&amp;quot;)+ &amp;quot; Benchmark Result: &amp;quot; + total + &amp;quot;]&amp;quot;);
}

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&amp;gt;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();
            }
}
}
}

/*
stretch tree of depth 21     check: -1
2097152  trees of depth 4    check: -2097152
524288   trees of depth 6    check: -524288
131072   trees of depth 8    check: -131072
32768    trees of depth 10   check: -32768
8192     trees of depth 12   check: -8192
2048     trees of depth 14   check: -2048
512  trees of depth 16   check: -512
128  trees of depth 18   check: -128
32   trees of depth 20   check: -32
long lived tree of depth 20  check: -1
[Binary Trees-null Benchmark Result: 9909]

*/

// WITH NON-STATIC THE SAME CODE
stretch tree of depth 21     check: -1
2097152  trees of depth 4    check: -2097152
524288   trees of depth 6    check: -524288
131072   trees of depth 8    check: -131072
32768    trees of depth 10   check: -32768
8192     trees of depth 12   check: -8192
2048     trees of depth 14   check: -2048
512  trees of depth 16   check: -512
128  trees of depth 18   check: -128
32   trees of depth 20   check: -32
long lived tree of depth 20  check: -1
[Binary Trees-null Benchmark Result: 59492]

// WITH NON-STATIC AND INDY THE SAME CODE

}}}

== Fib - Groovy++ ==

{{{
@Typed class Fib {
    static int fibStaticTernary (int n) {
        n &amp;gt;= 2 ? fibStaticTernary(n-1) + fibStaticTernary(n-2) : 1
    }

    static int fibStaticIf (int n) {
        if(n &amp;gt;= 2) fibStaticIf(n-1) + fibStaticIf(n-2) else 1
    }

    int fibTernary (int n) {
        n &amp;gt;= 2 ? fibTernary(n-1) + fibTernary(n-2) : 1
    }

    int fibIf (int n) {
        if(n &amp;gt;= 2) fibIf(n-1) + fibIf(n-2) else 1
    }

    public static void main(String[] args) {
        def start = System.currentTimeMillis()
        Fib.fibStaticTernary(40)
        println(&amp;quot;Groovypp(static ternary): &lt;span class="cp"&gt;${&lt;/span&gt;&lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;currentTimeMillis&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="cp"&gt;}&lt;/span&gt;ms&amp;quot;)

        start = System.currentTimeMillis()
        Fib.fibStaticIf(40)
        println(&amp;quot;Groovypp(static if): &lt;span class="cp"&gt;${&lt;/span&gt;&lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;currentTimeMillis&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="cp"&gt;}&lt;/span&gt;ms&amp;quot;)

        start = System.currentTimeMillis()
        new Fib().fibTernary(40)
        println(&amp;quot;Groovypp(instance ternary): &lt;span class="cp"&gt;${&lt;/span&gt;&lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;currentTimeMillis&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="cp"&gt;}&lt;/span&gt;ms&amp;quot;)

        start = System.currentTimeMillis()
        new Fib().fibIf(40)
        println(&amp;quot;Groovypp(instance if): &lt;span class="cp"&gt;${&lt;/span&gt;&lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;currentTimeMillis&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="cp"&gt;}&lt;/span&gt;ms&amp;quot;)
    }
}

/*

Groovypp(static ternary): 912ms
Groovypp(static if): 909ms
Groovypp(instance ternary): 928ms
Groovypp(instance if): 927ms
*/
}}}

== Fib - Groovy 1.8.2 ==
{{{
class Fib {
    static int fibStaticTernary (int n) {
        n &amp;gt;= 2 ? fibStaticTernary(n-1) + fibStaticTernary(n-2) : 1
    }

    static int fibStaticIf (int n) {
        if(n &amp;gt;= 2) fibStaticIf(n-1) + fibStaticIf(n-2) else 1
    }

    int fibTernary (int n) {
        n &amp;gt;= 2 ? fibTernary(n-1) + fibTernary(n-2) : 1
    }

    int fibIf (int n) {
        if(n &amp;gt;= 2) fibIf(n-1) + fibIf(n-2) else 1
    }

    public static void main(String[] args) {
        def start = System.currentTimeMillis()
        Fib.fibStaticTernary(40)
        println(&amp;quot;Groovy(static ternary): &lt;span class="cp"&gt;${&lt;/span&gt;&lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;currentTimeMillis&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="cp"&gt;}&lt;/span&gt;ms&amp;quot;)

        start = System.currentTimeMillis()
        Fib.fibStaticIf(40)
        println(&amp;quot;Groovy(static if): &lt;span class="cp"&gt;${&lt;/span&gt;&lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;currentTimeMillis&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="cp"&gt;}&lt;/span&gt;ms&amp;quot;)

        start = System.currentTimeMillis()
        new Fib().fibTernary(40)
        println(&amp;quot;Groovy(instance ternary): &lt;span class="cp"&gt;${&lt;/span&gt;&lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;currentTimeMillis&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="cp"&gt;}&lt;/span&gt;ms&amp;quot;)

        start = System.currentTimeMillis()
        new Fib().fibIf(40)
        println(&amp;quot;Groovy(instance if): &lt;span class="cp"&gt;${&lt;/span&gt;&lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;currentTimeMillis&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="cp"&gt;}&lt;/span&gt;ms&amp;quot;)
    }
}

/*
 Groovy(static ternary): 16335ms
Groovy(static if): 16045ms
Groovy(instance ternary): 35477ms
Groovy(instance if): 35751ms

*/
}}}
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Anonymous</dc:creator><pubDate>Wed, 22 Jan 2014 10:30:42 -0000</pubDate><guid>https://sourceforge.netdee9b7ac41abe059a8465747309194f08d57a39a</guid></item></channel></rss>