Skip to content

Instantly share code, notes, and snippets.

View stepancheg's full-sized avatar

Stepan Koltsov stepancheg

View GitHub Profile
@stepancheg
stepancheg / ManagedSeq.scala
Created November 15, 2009 19:43
ManagedSeq
import scala.collection._
import scala.collection.generic._
import scala.collection.mutable.Builder
trait ManagedResource[+A] { self =>
def acquireFor[R](f: A => R): R
def map[B](g: A => B): ManagedResource[B] = new ManagedResource[B] {
override def acquireFor[R](f: B => R) = {
self.acquireFor(x => f(g(x)))
import java.io._
import java.nio._
val f = new File("/dev/zero")
val size = 10000
val count = 100000
def readUsingInputStream() {
val is = new FileInputStream(f)
def profile[T](what: String)(action: => T) = {
val start = System.currentTimeMillis()
val r = action
val delta = System.currentTimeMillis() - start
println(what + ": " + delta + "; " + r)
}
@stepancheg
stepancheg / 20m.scala
Created November 23, 2009 17:15
Collections.sort
case class A(value: Int)
def sort(a: java.util.List[A]) = {
val c = new java.util.Comparator[A] {
override def compare(x: A, y: A) = x.value - y.value
}
java.util.Collections.sort(a, c)
}
def profile[T](what: String)(action: => T) = {
@stepancheg
stepancheg / sort.cpp
Created November 23, 2009 17:27
sort.cpp
#include <sys/time.h>
#include <time.h>
#include <stdlib.h>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
@stepancheg
stepancheg / arrays-sort.scala
Created November 23, 2009 17:37
Arrays.sort
def sort(a: Array[Int]) = {
java.util.Arrays.sort(a)
}
def profile[T](what: String)(action: => T) = {
val start = System.currentTimeMillis()
val r = action
val delta = System.currentTimeMillis() - start
println(what + ": " + delta + "; " + r)
}
<target name="getjar-helper2" unless="skip.download">
<echo>Getting ${url} to ${file}</echo>
</target>
<target name="getjar-helper">
<available property="skip.download" file="${file}"/>
<antcall target="getjar-helper2"/>
</target>
<macrodef name="getjar">
Index: build.xml
===================================================================
--- build.xml (revision 20173)
+++ build.xml (working copy)
@@ -5,6 +5,47 @@
<description>
SuperSabbus for Scala core, builds the scala library and compiler. It can also package it as a simple distribution, tests it for stable bootstrapping and against the Scala test suite.
</description>
+
+ <target name="getjar-helper2" unless="skip.download">
@stepancheg
stepancheg / main.java
Created January 8, 2010 03:28
HashMap vs. IdentityHashMap
import java.util.*;
class Main {
private static final Random random = new Random();
static class A {
} /// end of A
static class B {
private final int hashCode = random.nextInt();
#include <stdio.h>
#include <sys/time.h>
#include <stdlib.h>
#include <stdint.h>
const uint64_t count = 1000 * 1000 * 1000;
static uint64_t microseconds() {
struct timeval tv;
if (0 != gettimeofday(&tv, NULL))