-
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.
optimize acts/waypoints/dialogs titles
add benchmark optimize calc header
- Loading branch information
Showing
11 changed files
with
319 additions
and
237 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
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 |
---|---|---|
@@ -1,27 +1,102 @@ | ||
package d2editor_test | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/vitalick/go-d2editor" | ||
"testing" | ||
) | ||
|
||
func benchOne(b *testing.B, ch chan []byte) { | ||
func createEmpty(b *testing.B) *d2editor.Character { | ||
c, _ := d2editor.NewEmptyCharacter(97) | ||
bts, _ := c.GetCorrectBytes() | ||
ch <- bts | ||
return c | ||
} | ||
|
||
func BenchmarkCreateEmpty(b *testing.B) { | ||
var c = make(chan []byte) | ||
count := 0 | ||
func openOne(b *testing.B) *d2editor.Character { | ||
c, _ := d2editor.Open("LoD-Druid.d2s") | ||
return c | ||
} | ||
|
||
func openJSON(b *testing.B) *d2editor.Character { | ||
c, _ := d2editor.OpenJSON("LoD-Druid2.json") | ||
return c | ||
} | ||
|
||
func saveOne(b *testing.B, c *d2editor.Character) { | ||
c.GetBytes() | ||
} | ||
|
||
func saveJSON(b *testing.B, c *d2editor.Character) { | ||
json.Marshal(c) | ||
} | ||
|
||
func createSaveEmpty(b *testing.B) { | ||
saveOne(b, createEmpty(b)) | ||
} | ||
|
||
func openSaveOne(b *testing.B) { | ||
saveOne(b, openOne(b)) | ||
} | ||
|
||
func openSaveJSON(b *testing.B) { | ||
saveJSON(b, openJSON(b)) | ||
} | ||
|
||
func BenchmarkCreateEmptyConcurrently(b *testing.B) { | ||
for range make([]bool, b.N) { | ||
go createEmpty(b) | ||
} | ||
} | ||
|
||
func BenchmarkSaveEmptyConcurrently(b *testing.B) { | ||
c := createEmpty(b) | ||
b.ResetTimer() | ||
for range make([]bool, b.N) { | ||
go benchOne(b, c) | ||
go saveOne(b, c) | ||
} | ||
for range c { | ||
count++ | ||
if count == b.N { | ||
break | ||
} | ||
} | ||
|
||
func BenchmarkCreateSaveEmptyConcurrently(b *testing.B) { | ||
for range make([]bool, b.N) { | ||
go createSaveEmpty(b) | ||
} | ||
} | ||
|
||
func BenchmarkOpenConcurrently(b *testing.B) { | ||
for range make([]bool, b.N) { | ||
go openOne(b) | ||
} | ||
} | ||
|
||
func BenchmarkSaveFileConcurrently(b *testing.B) { | ||
c := openOne(b) | ||
b.ResetTimer() | ||
for range make([]bool, b.N) { | ||
go saveOne(b, c) | ||
} | ||
} | ||
|
||
func BenchmarkOpenSaveConcurrently(b *testing.B) { | ||
for range make([]bool, b.N) { | ||
go openSaveOne(b) | ||
} | ||
} | ||
|
||
func BenchmarkOpenJSONConcurrently(b *testing.B) { | ||
for range make([]bool, b.N) { | ||
go openJSON(b) | ||
} | ||
} | ||
|
||
func BenchmarkSaveJSONConcurrently(b *testing.B) { | ||
c := openJSON(b) | ||
b.ResetTimer() | ||
for range make([]bool, b.N) { | ||
go saveJSON(b, c) | ||
} | ||
} | ||
|
||
func BenchmarkOpenSaveJSONConcurrently(b *testing.B) { | ||
for range make([]bool, b.N) { | ||
go openSaveJSON(b) | ||
} | ||
close(c) | ||
} |
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
Oops, something went wrong.