Skip to content

Commit

Permalink
improve benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
gombiuda committed Feb 7, 2014
1 parent 8bc2c04 commit baf6787
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
6 changes: 5 additions & 1 deletion benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ void send_all(int c, int n, int *fds) {
Random rnd(301);
for (int i = 0; i < c; i++) {
for (int j = 0; j < n; j++) {
order.operation = 0x02;
if (rnd.OneIn(3)) {
order.operation = 0x02;
} else {
order.operation = 0x01;
}
order.id = (i << 8) + j;
order.from = rnd.next() % 128;
order.to = rnd.next() % 128 + order.from;
Expand Down
4 changes: 3 additions & 1 deletion benchmark_ringbuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "random.h"
#include "order.h"
#include "ringbuffer.h"
#include "sequencer.h"

using namespace std;

Expand Down Expand Up @@ -48,7 +49,8 @@ void consume(RingBuffer<Order> *ring, int n) {

int main() {
struct timeval start, end;
RingBuffer<Order> *ring = new RingBuffer<Order>(65536);
Sequencer *sequencer = new Sequencer(65536);
RingBuffer<Order> *ring = new RingBuffer<Order>(sequencer);
gettimeofday(&start, NULL);
thread producer(produce, ring, N);
thread consumer(consume, ring, N);
Expand Down
8 changes: 4 additions & 4 deletions benchmark_train.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
using namespace std;

#define N 65536
#define STATION_N 128
#define SEAT_N 2048
#define STATION_N 64
#define SEAT_N 512
#define MILLION 1000000

int main() {
Expand Down Expand Up @@ -45,8 +45,8 @@ int main() {
}
gettimeofday(&end, NULL);
double use_time = (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / (double)MILLION;
cout << "Process " << N << " requests" << endl;
cout << "Process " << N << " operations" << endl;
cout << "Use time: " << use_time << " s" << endl;
cout << "Request per second: " << N / use_time << endl;
cout << "ops: " << (long)(N / use_time) << endl;
return 0;
}
2 changes: 1 addition & 1 deletion server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Server::Server(const char* host_, int port_) : host(host_), port(port_) {
sequencer = new Sequencer(65536);
ring = new RingBuffer<Order>(sequencer);
train = new Train(0, 128, 512);
train = new Train(0, 64, 512);
}

void Server::start(int backlog) {
Expand Down

0 comments on commit baf6787

Please sign in to comment.