Skip to content

Instantly share code, notes, and snippets.

//Scala parallel version smallpt of http://www.cnblogs.com/miloyip/archive/2010/07/07/languages_brawl_GI.html
package parallel
class RandomLCG(var seed:Long) {
def nextDouble(): Double = {
seed = (214013L * seed + 2531011L) % 0x100000000L
seed * (1.0 / 4294967296.0)
}
}
@Arbow
Arbow / coroutine-benchmark.py
Created January 30, 2010 07:43
Just like http://gist.github.com/290451, but stackless version
#!/usr/bin/env python
#coding=utf-8
import stackless
import sys
import time
per_thread_requests = 10000
def receive_task():
for i in xrange(0, per_thread_requests):
@Arbow
Arbow / KilimBenchmarkMain.java
Created January 30, 2010 06:24
Kilim Message send/receive Benchmark
package coroutine.kilim.benchmark;
import java.util.concurrent.CountDownLatch;
import kilim.Mailbox;
import kilim.Pausable;
import kilim.Task;
public class Main {
@Arbow
Arbow / CoroutineBenchmark.scala
Created January 28, 2010 16:52
Scala message send/receive benchmark
import scala.actors.{Actor}
import scala.actors.Actor._
import java.util.concurrent.CountDownLatch
object Main {
val PROCESSER_COUNT=Runtime.getRuntime().availableProcessors()
var perThreadRequests=10000
//From http://hg.openjdk.java.net/jdk7/jdk7/jdk/raw-file/bfd7abda8f79/src/share/classes/java/util/TimSort.java
/*
* Copyright 2009 Google Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
@Arbow
Arbow / gist:257036
Created December 15, 2009 15:53
golang prime generator
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import "fmt"
// Send the sequence 2, 3, 4, ... to channel 'ch'.
func generate(ch chan int) {
@Arbow
Arbow / gist:257034
Created December 15, 2009 15:52
stackless python prime generator
# 相比sieve.go,内存占用少很多哦 - 对比 http://gist.github.com/257036
import stackless
def generate(channel):
i = 2
while True:
channel.send(i)
i = i+1
def filter_prime(in_chan, out_chan, prime):
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import org.apache.commons.codec.binary.Base64;
/**
/**
* 根据概率产生相应奖品
*
* @return 相应对应的号码
*/
@SuppressWarnings("unchecked")
public static int getAward() {
Map result = new LinkedHashMap();
for (int i = 0; i < 500; i++) {
public <T extends Room> List<Integer> getBatchPlayerAmountOfRooms(List<T> rooms) {
if (rooms == null || rooms.size() == 0)
return new ArrayList<Integer>(0);
Collection<String> uidList = FPUtils.map(rooms, new FPUtils.MapFunc<T, String>() {
@Override
public String map(T room) {
return roomCacheKey(room);
}
});