<commit_before>import scala.actors.Actor
import scala.actors.Actor._
import akka.actor.Actor.actorOf
import scala.annotation.tailrec

case object Msg

object global {
    val latch = new java.util.concurrent.CountDownLatch(1)
}

class ThreadedReceiver(n: Long) extends Actor {
    def act() {
        var i: Long = 0
        while (i < n)
            receive {
                case Msg => i += 1
            }
       Console println "received " + i + " messages"
    }
}

class ThreadlessReceiver(n: Long) extends Actor {
    def rcv(rest: Long) {
        react {
            case Msg => if (rest > 0) rcv(rest-1);
        }
    }
    def act() {
        rcv(n);
    }
}

class AkkaReceiver(n: Long) extends akka.actor.Actor {
    var received: Long = 0
    def receive = {
        case Msg =>
            received += 1
            if (received == n) {
                global.latch.countDown
                self.exit
            }
    }
}

object MailboxPerformance {
    def usage() {
        Console println "usage: (threaded|threadless|akka) (num_threads) (msgs_per_thread)"
    }
    def cr_threads(receiver: { def !(msg:Any): Unit }, threads: Int, msgs: Int) {
            for (i <- 0 until threads)
                (new java.lang.Thread {
                    override def run() {
                        for (j <- 0 until msgs)
                            receiver ! Msg
                    }
                }).start
    }
    def main(args: Array[String]) = {
        if (args.size != 3) {
            usage
            throw new IllegalArgumentException("")
        }
        val threads = args(1).toInt
        val msgs = args(2).toInt
        if (args(0) == "threaded") {
            cr_threads((new ThreadedReceiver(threads*msgs)).start, threads, msgs)
        }
        else if (args(0) == "threadless") {
            cr_threads((new ThreadlessReceiver(threads*msgs)).start, threads, msgs)
        }
        else if (args(0) == "akka") {
            val a = actorOf(new AkkaReceiver(threads*msgs)).start
            // akka actors define operator! with implicit argument
            cr_threads(new AnyRef { def !(what: Any) { a ! what } }, threads, msgs)
            global.latch.await
        }
        else usage
    }
}
<commit_msg>benchmark update<commit_after>import scala.actors.Actor
import scala.actors.Actor._
import akka.actor.Actor.actorOf
import scala.annotation.tailrec

case object Msg

object global {
    val latch = new java.util.concurrent.CountDownLatch(1)
}

class ThreadedReceiver(n: Long) extends Actor {
    override def act() {
        var i: Long = 0
        while (i < n)
            receive {
                case Msg => i += 1
            }
    }
}

class ThreadlessReceiver(n: Long) extends Actor {
    var i: Long = 0
    override def act() {
        react {
            case Msg =>
                i += 1
                if (i < n) act
        }
    }
}

class AkkaReceiver(n: Long) extends akka.actor.Actor {
    var received: Long = 0
    def receive = {
        case Msg =>
            received += 1
            if (received == n) {
                global.latch.countDown
                self.exit
            }
    }
}

object MailboxPerformance {
    def usage() {
        Console println "usage: (threaded|threadless|akka) (num_threads) (msgs_per_thread)"
    }
    def main(args: Array[String]) = {
        if (args.size != 3) {
            usage
            throw new IllegalArgumentException("")
        }
        val threads = args(1).toInt
        val msgs = args(2).toInt
        val impl = List("threaded", "threadless", "akka").indexOf(args(0))
        if (impl == -1) {
            usage
        }
        else if (impl < 2) {
            val rcvRef = if (impl == 0) (new ThreadedReceiver(threads*msgs)).start
                         else (new ThreadlessReceiver(threads*msgs)).start
            for (i <- 0 until threads)
                (new java.lang.Thread {
                    override def run() { for (_ <- 0 until msgs) rcvRef ! Msg }
                }).start
        }
        else {
            val rcvRef = actorOf(new AkkaReceiver(threads*msgs)).start
            for (i <- 0 until threads)
                (new java.lang.Thread {
                    override def run() { for (_ <- 0 until msgs) rcvRef ! Msg }
                }).start
            global.latch.await
        }
    }
}

{'fraction_non_alphanumeric': 0.11037173015144562, 'fraction_numerical': 0.007572280862781092, 'mean_word_length': 1.5536028119507908, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7230350', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1273, 'n_words': 342}