IoTagDB *IoTagDB_proto(void *state) { IoObject *self = IoObject_new(state); IoObject_tag_(self, IoTagDB_newTag(state)); IoState_registerProtoWithFunc_(state, self, IoTagDB_proto); { IoMethodTable methodTable[] = { {"setPath", IoTagDB_setPath}, {"open", IoTagDB_open}, {"close", IoTagDB_close}, {"atKeyPutTags", IoTagDB_atKeyPutTags}, {"tagsAtKey", IoTagDB_tagsAtKey}, {"removeKey", IoTagDB_removeKey}, {"keysForTags", IoTagDB_keysForTags}, {"size", IoTagDB_size}, {"symbolForId", IoTagDB_symbolForId}, {"idForSymbol", IoTagDB_idForSymbol}, {"keyAtIndex", IoTagDB_keyAtIndex}, {"delete", IoTagDB_delete}, {"allUniqueTagIds", IoTagDB_allUniqueTagIds}, {NULL, NULL}, }; IoObject_addMethodTable_(self, methodTable); } IoObject_setDataPointer_(self, TagDB_new()); return self; }
int main (int argc, const char * argv[]) { TagDB *tagDB = TagDB_new(); int i; int max = 10000; printf("\ntagdb performance tests:\n"); Timer_Begin(); remove("testdb"); TagDB_setPath_(tagDB, "testdb"); if(TagDB_open(tagDB) == 0) { exit(-1); } Timer_EndShowNumPerSecond(TagDB_size(tagDB), " load-record-from-disk op"); printf(" inserting...\n"); if (TagDB_size(tagDB) < max) { Timer_Begin(); for (i = TagDB_size(tagDB); i < max; i = i + 1) { TagIdArray *tags = TagIdArray_new(); tagid_t tid = rand() % 3; //printf("inserting %i\n", i); TagIdArray_append_(tags, tid); tid += 1 + rand() % 3; TagIdArray_append_(tags, tid); tid += 1 + rand() % 3; TagIdArray_append_(tags, tid); TagDB_atKey_putTags_(tagDB, i, tags); TagIdArray_free(tags); } Timer_EndShowNumPerSecond(max, "insert"); } printf(" searching...\n"); { int n, numSearches = 10000; TagIdArray *tags = TagIdArray_new(); KeyIdArray *results; TagIdArray_append_(tags, rand() % 5); TagIdArray_append_(tags, 3 + rand() % 3); Timer_Begin(); for(n = 0; n < numSearches; n ++) { results = TagDB_keysForTags_(tagDB, tags); } //printf("%i matches found\n", (int)results->size); TagIdArray_free(tags); Timer_EndShowNumPerSecond((numSearches * TagDB_size(tagDB)), "records searche"); } printf(" closing...\n"); TagDB_close(tagDB); printf(" reopening...\n"); Timer_Begin(); TagDB_open(tagDB); Timer_EndShowNumPerSecond(TagDB_size(tagDB), "records read"); printf(" removing...\n"); { size_t numToRemove = TagDB_size(tagDB); Timer_Begin(); for (i = 0; i < numToRemove; i = i + 1) { TagDB_removeKey_(tagDB, i); } Timer_EndShowNumPerSecond(numToRemove, "remove"); } TagDB_close(tagDB); TagDB_delete(tagDB); printf("\n"); return 0; }
IoTagDB *IoTagDB_rawClone(IoTagDB *proto) { IoObject *self = IoObject_rawClonePrimitive(proto); IoObject_setDataPointer_(self, TagDB_new()); return self; }