-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86e0da1
commit 7ce3378
Showing
2 changed files
with
46 additions
and
14 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package beeorm | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
type loadByIDBenchmarkEntity struct { | ||
ORM `orm:"localCache;redisCache"` | ||
ID uint | ||
Name string | ||
Int int | ||
Bool bool | ||
Float float64 | ||
Decimal float32 `orm:"decimal=10,2"` | ||
} | ||
|
||
// BenchmarkLoadByIDLocalCache-10 3572815 325.6 ns/op 152 B/op 6 allocs/op | ||
func BenchmarkLoadByIDLocalCache(b *testing.B) { | ||
benchmarkLoadByIDCache(b, true, false) | ||
} | ||
|
||
// BenchmarkLoadByIDRedisCache-10 1695 603416 ns/op 421 B/op 15 allocs/op | ||
func BenchmarkLoadByIDRedisCache(b *testing.B) { | ||
benchmarkLoadByIDCache(b, false, true) | ||
} | ||
|
||
func benchmarkLoadByIDCache(b *testing.B, local, redis bool) { | ||
entity := &loadByIDBenchmarkEntity{} | ||
registry := &Registry{} | ||
registry.RegisterLocalCache(10000) | ||
engine := PrepareTables(nil, registry, 5, 6, "", entity) | ||
schema := engine.GetRegistry().GetEntitySchemaForEntity(entity).(*entitySchema) | ||
schema.DisableCache(!local, !redis) | ||
|
||
entity.Name = "Name" | ||
entity.Int = 1 | ||
entity.Float = 1.3 | ||
entity.Decimal = 12.23 | ||
engine.Flush(entity) | ||
_ = engine.LoadByID(1, entity) | ||
b.ResetTimer() | ||
b.ReportAllocs() | ||
for n := 0; n < b.N; n++ { | ||
_ = engine.LoadByID(1, entity) | ||
} | ||
} |