omg optimize

pull/1/head
Jeff Becker 6 years ago
parent a4abfc0e9d
commit b949e61752
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

4
.gitignore vendored

@ -9,4 +9,6 @@
llarpd
*.test
*.bin
*.bin
callgrind.*

@ -65,11 +65,13 @@ $(REPO)/test/%.cpp.bin: $(REPO)/test/%.cpp
$(CXX) $(REQUIRED_CXXFLAGS) $< -o $<.bin $(TEST_LDFLAGS)
mv $<.bin $<.test
$<.test
valgrind --tool=callgrind $<.test
$(REPO)/test/%.c.bin: $(REPO)/test/%.c
$(CC) $(REQUIRED_CFLAGS) $< -o $<.bin $(TEST_LDFLAGS)
mv $<.bin $<.test
$<.test
valgrind --tool=callgrind $<.test
$(EXE): $(DAEMON_OBJ) $(STATIC_LIB)
$(CXX) $(DAEMON_OBJ) $(STATIC_LIB) $(LIB_LDFLAGS) -o $(EXE)

@ -5,6 +5,7 @@
#include <mutex>
#include <queue>
struct llarp_ev_caller {
static void *operator new(size_t sz) {
return llarp::Alloc<llarp_ev_caller>();
@ -21,37 +22,34 @@ struct llarp_ev_caller {
bool appendCall(void *user) {
std::unique_lock<std::mutex> lock(access);
bool should = pending.size() == 0;
llarp_ev_async_call *call =
new llarp_ev_async_call{loop, this, user, this->work};
pending.push(call);
return should;
pending.emplace_back(std::move(llarp_ev_async_call{loop, this, user, this->work}));
return true;
}
bool appendManyCalls(void **users, size_t n) {
std::unique_lock<std::mutex> lock(access);
bool should = pending.size() == 0;
while (n--) {
pending.push(new llarp_ev_async_call{loop, this, *users, this->work});
pending.emplace_back(std::move(llarp_ev_async_call{loop, this, *users, this->work}));
users++;
}
return should;
return true;
}
void Call() {
std::unique_lock<std::mutex> lock(access);
while (pending.size() > 0) {
auto sz = pending.size();
while (sz > 0) {
auto &front = pending.front();
front->work(front);
pending.pop();
delete front;
front.work(&front);
pending.pop_front();
--sz;
}
}
std::mutex access;
struct llarp_ev_loop *loop;
uv_async_t async;
std::queue<llarp_ev_async_call *> pending;
std::deque<llarp_ev_async_call> pending;
llarp_ev_work_func work;
};

@ -35,14 +35,14 @@ int main(int argc, char *argv[]) {
struct bench_main b_main;
struct llarp_threadpool *tp;
llarp_mem_jemalloc();
llarp_mem_std();
llarp_crypto_libsodium_init(&b_main.crypto);
llarp_ev_loop_alloc(&b_main.ev);
tp = llarp_init_threadpool(2);
b_main.num = 10000000;
b_main.jobs = 10000;
b_main.num = 100000;
b_main.jobs = 1000;
b_main.completed = 0;
llarp_sharedkey_t key;
b_main.crypto.randbytes(key, sizeof(llarp_sharedkey_t));

Loading…
Cancel
Save