(b *testing.B)
| 973 | } |
| 974 | |
| 975 | func BenchmarkDatabaseGetRev(b *testing.B) { |
| 976 | base.DisableTestLogging(b) |
| 977 | |
| 978 | db, ctx := setupTestDB(b) |
| 979 | defer db.Close(ctx) |
| 980 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, b, db) |
| 981 | |
| 982 | body := Body{"foo": "bar", "rev": "1-a"} |
| 983 | _, _, _ = collection.PutExistingRevWithBody(ctx, "doc1", body, []string{"1-a"}, false, ExistingVersionWithUpdateToHLV) |
| 984 | |
| 985 | largeDoc := make([]byte, 1000000) |
| 986 | longBody := Body{"val": string(largeDoc), "rev": "1-a"} |
| 987 | _, _, _ = collection.PutExistingRevWithBody(ctx, "doc2", longBody, []string{"1-a"}, false, ExistingVersionWithUpdateToHLV) |
| 988 | |
| 989 | var shortWithAttachmentsDataBody Body |
| 990 | shortWithAttachmentsData := `{"test": true, "_attachments": {"hello.txt": {"data":"aGVsbG8gd29ybGQ="}}, "rev":"1-a"}` |
| 991 | _ = base.JSONUnmarshal([]byte(shortWithAttachmentsData), &shortWithAttachmentsDataBody) |
| 992 | _, _, _ = collection.PutExistingRevWithBody(ctx, "doc3", shortWithAttachmentsDataBody, []string{"1-a"}, false, ExistingVersionWithUpdateToHLV) |
| 993 | |
| 994 | b.Run("ShortLatest", func(b *testing.B) { |
| 995 | for n := 0; n < b.N; n++ { |
| 996 | _, _ = collection.GetRev(ctx, "doc1", "", false, nil) |
| 997 | } |
| 998 | }) |
| 999 | b.Run("LongLatest", func(b *testing.B) { |
| 1000 | for n := 0; n < b.N; n++ { |
| 1001 | _, _ = collection.GetRev(ctx, "doc2", "", false, nil) |
| 1002 | } |
| 1003 | }) |
| 1004 | b.Run("ShortWithAttachmentsLatest", func(b *testing.B) { |
| 1005 | for n := 0; n < b.N; n++ { |
| 1006 | _, _ = collection.GetRev(ctx, "doc3", "", false, nil) |
| 1007 | } |
| 1008 | }) |
| 1009 | |
| 1010 | updateBody := Body{"rev": "2-a"} |
| 1011 | _, _, _ = collection.PutExistingRevWithBody(ctx, "doc1", updateBody, []string{"2-a", "1-a"}, false, ExistingVersionWithUpdateToHLV) |
| 1012 | _, _, _ = collection.PutExistingRevWithBody(ctx, "doc2", updateBody, []string{"2-a", "1-a"}, false, ExistingVersionWithUpdateToHLV) |
| 1013 | _, _, _ = collection.PutExistingRevWithBody(ctx, "doc3", updateBody, []string{"2-a", "1-a"}, false, ExistingVersionWithUpdateToHLV) |
| 1014 | |
| 1015 | b.Run("ShortOld", func(b *testing.B) { |
| 1016 | for n := 0; n < b.N; n++ { |
| 1017 | _, _ = collection.GetRev(ctx, "doc1", "1-a", false, nil) |
| 1018 | } |
| 1019 | }) |
| 1020 | b.Run("LongOld", func(b *testing.B) { |
| 1021 | for n := 0; n < b.N; n++ { |
| 1022 | _, _ = collection.GetRev(ctx, "doc2", "1-a", false, nil) |
| 1023 | } |
| 1024 | }) |
| 1025 | b.Run("ShortWithAttachmentsOld", func(b *testing.B) { |
| 1026 | for n := 0; n < b.N; n++ { |
| 1027 | _, _ = collection.GetRev(ctx, "doc3", "1-a", false, nil) |
| 1028 | } |
| 1029 | }) |
| 1030 | } |
| 1031 | |
| 1032 | // Replicates delta patching work carried out by handleRev |
nothing calls this directly
no test coverage detected