benchmarks refreshed

This commit is contained in:
Alex Tkachman
2012-02-20 12:43:02 +02:00
parent 436c298e47
commit 5435594343
12 changed files with 102 additions and 36 deletions
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package binary_trees;
public class BinaryTrees { public class BinaryTrees {
@@ -1,3 +1,20 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package binary_trees;
val minDepth = 4 val minDepth = 4
fun main(args: Array<String>) { fun main(args: Array<String>) {
@@ -14,6 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
package flist;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
abstract public class FList<T> { abstract public class FList<T> {
@@ -1,4 +1,19 @@
package flist /*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package flist_kotlin
abstract class FList<T> { abstract class FList<T> {
abstract val head : T abstract val head : T
@@ -7,7 +22,7 @@ abstract class FList<T> {
abstract fun plus(element: T) : FList<T> abstract fun plus(element: T) : FList<T>
} }
class EmptyFList<T>() : FList<T> { class EmptyFList<T>() : FList<T>() {
override val head: T override val head: T
get() = throw java.util.NoSuchElementException() get() = throw java.util.NoSuchElementException()
@@ -17,14 +32,14 @@ class EmptyFList<T>() : FList<T> {
override fun plus(element: T) : FList<T> = OneElementFList<T>(element) override fun plus(element: T) : FList<T> = OneElementFList<T>(element)
} }
class OneElementFList<T> (override val head: T): FList<T> { class OneElementFList<T> (override val head: T): FList<T>() {
override val tail : EmptyFList<T> override val tail : EmptyFList<T>
get() = EmptyFList<T>() get() = EmptyFList<T>()
override fun plus(element: T) : FList<T> = StandardFList<T>(element, this) override fun plus(element: T) : FList<T> = StandardFList<T>(element, this)
} }
class StandardFList<T> (override val head: T, override val tail: FList<T>) : FList<T> { class StandardFList<T> (override val head: T, override val tail: FList<T>) : FList<T>() {
override fun plus(element: T) : FList<T> = StandardFList<T>(element, this) override fun plus(element: T) : FList<T> = StandardFList<T>(element, this)
} }
@@ -14,6 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
package lockperf;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
@@ -1,4 +1,20 @@
package lockperformance /*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package lockperf_kotlin
import std.io.* import std.io.*
import std.util.* import std.util.*
@@ -30,10 +46,10 @@ fun main(args: Array<String>) {
lock.lock() lock.lock()
try { try {
if (counter.get() == 100000000) { if (counter.get() == 100000000) {
countDown(); countDown()
break; break;
} else { } else {
counter.incrementAndGet(); counter.incrementAndGet()
} }
} }
finally { finally {
@@ -47,9 +63,6 @@ fun main(args: Array<String>) {
println(threadNum.toString() + " " + duration) println(threadNum.toString() + " " + duration)
if(threadNum < 2 * processors) if(threadNum < 2 * processors) threadNum++ else threadNum = 2*threadNum
threadNum = threadNum + 1
else
threadNum = threadNum * 2
} }
} }
@@ -14,6 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
package quicksort;
public class Quicksort { public class Quicksort {
public static void swap(int[] a, int i, int j) { public static void swap(int[] a, int i, int j) {
@@ -1,3 +1,19 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package quicksort package quicksort
fun IntArray.swap(i:Int, j:Int) { fun IntArray.swap(i:Int, j:Int) {
@@ -1,3 +1,4 @@
package spectralnorm_kotlin;
/* /*
* Copyright 2010-2012 JetBrains s.r.o. * Copyright 2010-2012 JetBrains s.r.o.
* *
@@ -1,4 +1,4 @@
package spectralnorm package spectralnorm_kotlin
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.NumberFormat; import java.text.NumberFormat;
@@ -1,19 +1,4 @@
/* package threadring;
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** /**
* The Computer Language Benchmarks Game * The Computer Language Benchmarks Game
* http://shootout.alioth.debian.org/ * http://shootout.alioth.debian.org/
@@ -1,4 +1,20 @@
package threadring /*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package threadring_kotlin
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.concurrent.atomic.*; import java.util.concurrent.atomic.*;
@@ -24,19 +40,14 @@ fun main(args: Array<String>) {
System.out?.println("[ThreadRing-" + System.getProperty("project.name")+ " Benchmark Result: " + total + "]") System.out?.println("[ThreadRing-" + System.getProperty("project.name")+ " Benchmark Result: " + total + "]")
} }
class TokenMessage(val nodeId : Int, value: Int, val isStop: Boolean) : AtomicInteger(value){ class TokenMessage(val nodeId : Int, value: Int, val isStop: Boolean) : AtomicInteger(value)
}
class ThreadRing(val N: Int) { class ThreadRing(val N: Int) {
val executor = Executors.newFixedThreadPool(MAX_THREADS).sure() val executor = Executors.newFixedThreadPool(MAX_THREADS).sure()
val nodes : Array<Node> = Array<Node>(MAX_NODES+1, { Node(it+1) }) val nodes : Array<Node> = Array<Node>(MAX_NODES+1, { (it : Int) -> Node(it+1) });
{ {
connectNodes()
}
fun connectNodes() {
nodes[nodes.size-1] = nodes[0] nodes[nodes.size-1] = nodes[0]
for (i in 0..nodes.size-2) { for (i in 0..nodes.size-2) {
nodes[i].connect(nodes[i+1]); nodes[i].connect(nodes[i+1]);
@@ -46,6 +57,7 @@ class ThreadRing(val N: Int) {
fun sendMessage(m : TokenMessage) { fun sendMessage(m : TokenMessage) {
nodes[0].sendMessage(m) nodes[0].sendMessage(m)
} }
class Node(val nodeId : Int) : Runnable { class Node(val nodeId : Int) : Runnable {
val queue = LinkedBlockingQueue<TokenMessage>() val queue = LinkedBlockingQueue<TokenMessage>()
var isActive = false var isActive = false