-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed race 'issues' using a mutext. Looking at the benchmark the mutex is somewhat faster, using channels feel more golang though. This can be changed in the future.
- Loading branch information
Tobias Laving
committed
Jul 20, 2020
1 parent
5419143
commit 0daafc4
Showing
8 changed files
with
166 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ function log { | |
echo "Pre-push: $@" | ||
} | ||
log "Testing" | ||
go test ./... | ||
make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package benchmarks | ||
|
||
import ( | ||
"os/exec" | ||
"sync" | ||
"testing" | ||
) | ||
|
||
type wCmdChan struct { | ||
c *exec.Cmd | ||
err error | ||
done chan bool | ||
} | ||
|
||
func (w *wCmdChan) start() { | ||
go func() { | ||
w.err = w.c.Run() | ||
w.done <- true | ||
}() | ||
} | ||
|
||
func (w *wCmdChan) check() bool { | ||
return <-w.done | ||
} | ||
|
||
type wCmdMutext struct { | ||
c *exec.Cmd | ||
err error | ||
done bool | ||
sync.RWMutex | ||
} | ||
|
||
func (w *wCmdMutext) start() { | ||
w.Lock() | ||
w.err = w.c.Run() | ||
w.done = true | ||
w.Unlock() | ||
} | ||
|
||
func (w *wCmdMutext) check() bool { | ||
w.RLock() | ||
defer w.RUnlock() | ||
return w.done | ||
} | ||
|
||
func BenchmarkChan(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
cmd := exec.Command("ls", "-la") | ||
w := wCmdChan{ | ||
c: cmd, | ||
done: make(chan bool), | ||
} | ||
w.start() | ||
for w.check() != true { | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkMutex(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
cmd := exec.Command("ls", "-la") | ||
w := wCmdMutext{ | ||
c: cmd, | ||
done: false, | ||
} | ||
w.start() | ||
for w.check() != true { | ||
} | ||
} | ||
} |