Skip to content

Commit 48960b7

Browse files
author
kpango
committed
use fastime
1 parent 8354c93 commit 48960b7

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

glg.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"sync/atomic"
1313
"time"
1414
"unsafe"
15+
16+
"github.com/kpango/fastime"
1517
)
1618

1719
// Glg is glg base struct
@@ -259,7 +261,7 @@ func (g *Glg) startTimerD() *Glg {
259261

260262
func (g *Glg) storeTime(format string) {
261263
buf := g.buffer.Get().([]byte)
262-
g.timer.Store(time.Now().AppendFormat(buf[:0], format))
264+
g.timer.Store(fastime.Now().AppendFormat(buf[:0], format))
263265
g.buffer.Put(buf[:0])
264266
}
265267

@@ -560,12 +562,12 @@ func FileWriter(path string, perm os.FileMode) *os.File {
560562
// HTTPLogger is simple http access logger
561563
func (g *Glg) HTTPLogger(name string, handler http.Handler) http.Handler {
562564
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
563-
start := time.Now()
565+
start := fastime.Now()
564566

565567
handler.ServeHTTP(w, r)
566568

567569
err := g.Logf("Method: %s\tURI: %s\tName: %s\tTime: %s",
568-
r.Method, r.RequestURI, name, time.Since(start).String())
570+
r.Method, r.RequestURI, name, fastime.Now().Sub(start).String())
569571

570572
if err != nil {
571573
err = g.Error(err)
@@ -579,12 +581,12 @@ func (g *Glg) HTTPLogger(name string, handler http.Handler) http.Handler {
579581
// HTTPLoggerFunc is simple http access logger
580582
func (g *Glg) HTTPLoggerFunc(name string, hf http.HandlerFunc) http.Handler {
581583
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
582-
start := time.Now()
584+
start := fastime.Now()
583585

584586
hf(w, r)
585587

586588
err := g.Logf("Method: %s\tURI: %s\tName: %s\tTime: %s",
587-
r.Method, r.RequestURI, name, time.Since(start).String())
589+
r.Method, r.RequestURI, name, fastime.Now().Sub(start).String())
588590

589591
if err != nil {
590592
err = g.Error(err)

images/bench.png

19.4 KB
Loading

0 commit comments

Comments
 (0)