Skip to content

Commit

Permalink
feat: add elapsed time for benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
zjregee committed Jul 2, 2024
1 parent 572db10 commit c6c5426
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
18 changes: 11 additions & 7 deletions benchmark/net/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func runServer(port string, stopChan chan interface{}, logger *logrus.Logger) {
for {
conn, err := listener.Accept()
if err != nil {
logger.Warnf("error occured when accept: %s", err.Error())
logger.Warnf("error occurred when accept: %s", err.Error())
continue
}
handleConnection(conn, logger)
Expand All @@ -43,17 +43,17 @@ func handleConnection(conn net.Conn, logger *logrus.Logger) {
for {
message, err := reader.ReadString('\n')
if err != nil {
logger.Warnf("error occured when read: %s",err.Error())
logger.Warnf("error occurred when read: %s",err.Error())
return
}
_, err = writer.WriteString(message)
if err != nil {
logger.Warnf("error occured when write: %s",err.Error())
logger.Warnf("error occurred when write: %s",err.Error())
return
}
err = writer.Flush()
if err != nil {
logger.Warnf("error occured when flush: %s",err.Error())
logger.Warnf("error occurred when flush: %s",err.Error())
return
}
}
Expand Down Expand Up @@ -83,6 +83,8 @@ func main() {
n := 100
messageLength := 48

start := time.Now()

for i := 0; i < m; i++ {
conn, err := net.Dial("tcp", port)
if err != nil {
Expand Down Expand Up @@ -113,9 +115,11 @@ func main() {
}
}

if (i % 10000 == 0) {
fmt.Printf("%vw passed\n", i / 10000)
}
conn.Close()
}

elapsed := time.Since(start)
minutes := int(elapsed.Minutes())
seconds := int(elapsed.Seconds()) % 60
fmt.Printf("the total time for net to execute %dk connections, with %d writes per connection, is: %d minutes %d seconds\n", m / 1000, n, minutes, seconds)
}
7 changes: 7 additions & 0 deletions benchmark/run_benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

go build -v -o ./net/main ./net
go build -v -o ./uring/main ./uring

./net/main
./uring/main
10 changes: 7 additions & 3 deletions benchmark/uring/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ func main() {
n := 100
messageLength := 48

start := time.Now()

for i := 0; i < m; i++ {
conn, err := net.Dial("tcp", port)
if err != nil {
Expand Down Expand Up @@ -177,9 +179,11 @@ func main() {
}
}

if (i % 10000 == 0) {
fmt.Printf("%vw passed\n", i / 10000)
}
conn.Close()
}

elapsed := time.Since(start)
minutes := int(elapsed.Minutes())
seconds := int(elapsed.Seconds()) % 60
fmt.Printf("the total time for uring to execute %dk connections, with %d writes per connection, is: %d minutes %d seconds\n", m / 1000, n, minutes, seconds)
}

0 comments on commit c6c5426

Please sign in to comment.