Skip to content

Instantly share code, notes, and snippets.

@kurorido
Last active August 29, 2015 14:03
Show Gist options
  • Save kurorido/f68160117403a4298add to your computer and use it in GitHub Desktop.
Save kurorido/f68160117403a4298add to your computer and use it in GitHub Desktop.
Insert 1M records into Couchbase
void prepareCouchBase() {
print("Testing Insert CouchBase");
CouchClient _dbclient;
CouchClient.connect([Uri.parse("http://10.1.4.112:8091/pools")], "default", "").then((CouchClient c) {
_dbclient = c;
}).then((_) {
int startTime = new DateTime.now().millisecondsSinceEpoch;
List<Future> futures = new List();
for (var i = 0; i < 1000000; i++) {
String key = i.toString();
String name = "name" + i.toString();
String desc = "desc" + i.toString();
List obj = [key, name, desc];
futures.add(_dbclient.add(key, UTF8.encode(JSON.encode(obj)))); // or set?
}
return Future.wait(futures).then((_) {
int endTime = new DateTime.now().millisecondsSinceEpoch;
int timeCost = endTime - startTime;
print(timeCost.toString() + "ms");
});
}).whenComplete(() {
_dbclient.close();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment