Last active
December 2, 2016 07:41
-
-
Save hisui/de66529734c8e289118f88be7e93e3d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name := "ds" | |
scalaVersion := "2.11.8" | |
// https://mvnrepository.com/artifact/com.google.cloud/google-cloud-datastore | |
libraryDependencies += "com.google.cloud" % "google-cloud-datastore" % "0.6.0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.cloud.datastore._ | |
import com.google.cloud.datastore.testing._ | |
object Main extends App { | |
def benchmark[A](title: String)(f: => A): A = { | |
val t0 = System.currentTimeMillis() | |
val o: A = f | |
val t1 = System.currentTimeMillis() | |
println(title) | |
println("-----") | |
println(s" - duration: ${t1 - t0}ms") | |
println(s" - returned: $o") | |
println("-----") | |
println("") | |
o | |
} | |
val ds = benchmark("get a service instance") { | |
DatastoreOptions.getDefaultInstance().getService() | |
} | |
val keyFactory = benchmark("create a key factory") { | |
ds.newKeyFactory().kind("Room") | |
} | |
val key = benchmark("create a key") { | |
ds.allocateId(keyFactory.newKey()) | |
} | |
val entity = Entity | |
.builder(key) | |
.set("title", StringValue.builder("untitled").build()) | |
.set("createdAt", DateTime.now()) | |
.set("updatedAt", DateTime.now()) | |
.build() | |
benchmark("put an entity") { | |
ds.put(entity) | |
} | |
val key1 = ds.newKeyFactory().setKind("Session").newKey(5629499534213120L) | |
benchmark("get an entity by a key: 5629499534213120") { | |
ds.get(key1, Array[ReadOption]() :_*) | |
} | |
val key2 = ds.newKeyFactory().setKind("Session").newKey(5649391675244544L) | |
benchmark("get an entity by a key: 5649391675244544") { | |
ds.get(key2, Array[ReadOption]() :_*) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment