Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.sbs.hotins
- import com.mongodb.casbah.Imports._
- import scala.actors.Actor
- object HotInsertApp {
- import HotInsert._
- def main(args: Array[String]):Unit = time(test3)
- }
- object HotInsert {
- val mongo = MongoConnection("localhost",27017)("HotInsDB")("HotTest")
- val data:Stream[() => DBObject] =
- (() => MongoDBObject("_id" -> new ObjectId,
- "Data" -> "X" * 20)) #:: data
- def time[R](block: => R): R = {
- val t0 = System.nanoTime()
- val result = block // call-by-name
- val t1 = System.nanoTime()
- println("Elapsed time: %f secs".format((t1.toFloat - t0) / 1000000000))
- result
- }
- def test1: Unit = {
- (1 to 500000) foreach ( _ =>
- mongo.insert(MongoDBObject("_id" -> new ObjectId,
- "Data" -> "X" * 20))
- )
- }
- def test2: Unit = {
- Range(1, 500000, 250).foreach(_ =>
- mongo.insert(data.map(_.apply).take(250).toList))
- }
- def test3: Unit = {
- Range(1, 500000, 250) foreach(s =>
- new Actor { override def act() = {
- mongo.insert(data.map(_.apply).take(250).toList)}}.start)
- }
- }
- /*
- Results for test3:
- ~/Projects/MongoDB/hotinsertioncontest ᐅ sbt run
- [info] Loading global plugins from /home/eof/.sbt/plugins
- [info] Loading project definition from /home/eof/Projects/MongoDB/hotinsertioncontest/project
- [info] Set current project to HotInsertionContest (in build file:/home/eof/Projects/MongoDB/hotinsertioncontest/)
- Multiple main classes detected, select one to run:
- [1] JettyLauncher
- [2] com.sbs.hotins.HotInsertApp
- Enter number: 2
- [info] Running com.sbs.hotins.HotInsertApp
- SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
- SLF4J: Defaulting to no-operation (NOP) logger implementation
- SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
- Elapsed time: 0,108003 secs
- [success] Total time: 7 s, completed 09-sep-2012 20:18:39
- */
Advertisement
Add Comment
Please, Sign In to add comment