InvoDB/invodb/main.cpp

63 lines
1.3 KiB
C++
Raw Normal View History

2021-10-05 14:41:15 +08:00
//
// Created by YuhangQ on 2021/9/24.
//
#include "main.h"
2021-10-28 23:15:15 +08:00
void benchmark() {
BTreeUUID *btree = new BTreeUUID(PageManager::Instance().allocate());
char uuid[33]; uuid[32] = '\0';
std::vector<std::pair<std::string, int>> v;
const int n = 1000000;
for(int i=0; i<n; i++) {
generateUUID(uuid);
int addr = PageManager::Instance().allocate();
v.push_back(std::make_pair(uuid, addr));
btree->insert(uuid, addr);
}
for(int i=0; i<1000000; i++) {
std::swap(v[rand()%v.size()], v[rand()%v.size()]);
}
for(int i=0; i<v.size(); i++) {
int addr = btree->find(v[0].first);
if(addr != v[0].second) {
printf("fuck\n");
exit(0);
}
}
}
2021-10-05 14:41:15 +08:00
int main() {
2021-10-28 23:15:15 +08:00
int t = time(0);
//srand(1635418590);
srand(1635423140);
printf("seed: %d\n", t);
2021-10-25 22:07:18 +08:00
system("rm -rf test.invodb && touch test.invodb");
2021-10-24 20:21:04 +08:00
2021-10-23 16:28:57 +08:00
PageManager::loadDatabase("test.invodb");
Collection::loadCollections();
2021-10-11 22:05:45 +08:00
2021-10-23 16:28:57 +08:00
PageManager& manager = PageManager::Instance();
2021-10-11 22:05:45 +08:00
2021-10-26 12:29:59 +08:00
2021-10-25 22:07:18 +08:00
Collection *col;
try {
col = &Collection::getCollection("hello");
} catch(const char *error) {
Collection::createCollection("hello");
}
2021-10-23 16:28:57 +08:00
JSON json("{\"hello\": 1}");
2021-10-25 22:07:18 +08:00
col->insert(json);
2021-10-28 23:15:15 +08:00
benchmark();
2021-10-26 21:26:48 +08:00
2021-10-05 14:41:15 +08:00
return 0;
}