diff options
author | =Corey Hulen <corey@hulen.com> | 2015-06-14 23:53:32 -0800 |
---|---|---|
committer | =Corey Hulen <corey@hulen.com> | 2015-06-14 23:53:32 -0800 |
commit | cf7a05f80f68b5b1c8bcc0089679dd497cec2506 (patch) | |
tree | 70007378570a6962d7c175ca96af732b71aeb6da /api/post_benchmark_test.go | |
download | chat-cf7a05f80f68b5b1c8bcc0089679dd497cec2506.tar.gz chat-cf7a05f80f68b5b1c8bcc0089679dd497cec2506.tar.bz2 chat-cf7a05f80f68b5b1c8bcc0089679dd497cec2506.zip |
first commit
Diffstat (limited to 'api/post_benchmark_test.go')
-rw-r--r-- | api/post_benchmark_test.go | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/api/post_benchmark_test.go b/api/post_benchmark_test.go new file mode 100644 index 000000000..861c687fb --- /dev/null +++ b/api/post_benchmark_test.go @@ -0,0 +1,130 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +package api + +import ( + "github.com/mattermost/platform/utils" + "testing" +) + +const ( + NUM_POSTS = 100 +) + +func BenchmarkCreatePost(b *testing.B) { + var ( + NUM_POSTS_RANGE = utils.Range{NUM_POSTS, NUM_POSTS} + ) + _, _, channel := SetupBenchmark() + + testPoster := NewAutoPostCreator(Client, channel.Id) + + // Benchmark Start + b.ResetTimer() + for i := 0; i < b.N; i++ { + testPoster.CreateTestPosts(NUM_POSTS_RANGE) + } +} + +func BenchmarkUpdatePost(b *testing.B) { + var ( + NUM_POSTS_RANGE = utils.Range{NUM_POSTS, NUM_POSTS} + UPDATE_POST_LEN = 100 + ) + _, _, channel := SetupBenchmark() + + testPoster := NewAutoPostCreator(Client, channel.Id) + posts, valid := testPoster.CreateTestPosts(NUM_POSTS_RANGE) + if valid == false { + b.Fatal("Unable to create test posts") + } + + for i := range posts { + posts[i].Message = utils.RandString(UPDATE_POST_LEN, utils.ALPHANUMERIC) + } + + // Benchmark Start + b.ResetTimer() + for i := 0; i < b.N; i++ { + for i := range posts { + if _, err := Client.UpdatePost(posts[i]); err != nil { + b.Fatal(err) + } + } + } +} + +func BenchmarkGetPosts(b *testing.B) { + var ( + NUM_POSTS_RANGE = utils.Range{NUM_POSTS, NUM_POSTS} + ) + _, _, channel := SetupBenchmark() + + testPoster := NewAutoPostCreator(Client, channel.Id) + testPoster.CreateTestPosts(NUM_POSTS_RANGE) + + // Benchmark Start + b.ResetTimer() + for i := 0; i < b.N; i++ { + Client.Must(Client.GetPosts(channel.Id, 0, NUM_POSTS, "")) + } +} + +func BenchmarkSearchPosts(b *testing.B) { + var ( + NUM_POSTS_RANGE = utils.Range{NUM_POSTS, NUM_POSTS} + ) + _, _, channel := SetupBenchmark() + + testPoster := NewAutoPostCreator(Client, channel.Id) + testPoster.CreateTestPosts(NUM_POSTS_RANGE) + + // Benchmark Start + b.ResetTimer() + for i := 0; i < b.N; i++ { + Client.Must(Client.SearchPosts("nothere")) + Client.Must(Client.SearchPosts("n")) + Client.Must(Client.SearchPosts("#tag")) + } +} + +func BenchmarkEtagCache(b *testing.B) { + var ( + NUM_POSTS_RANGE = utils.Range{NUM_POSTS, NUM_POSTS} + ) + _, _, channel := SetupBenchmark() + + testPoster := NewAutoPostCreator(Client, channel.Id) + testPoster.CreateTestPosts(NUM_POSTS_RANGE) + + etag := Client.Must(Client.GetPosts(channel.Id, 0, NUM_POSTS/2, "")).Etag + + // Benchmark Start + b.ResetTimer() + for i := 0; i < b.N; i++ { + Client.Must(Client.GetPosts(channel.Id, 0, NUM_POSTS/2, etag)) + } +} + +func BenchmarkDeletePosts(b *testing.B) { + var ( + NUM_POSTS_RANGE = utils.Range{NUM_POSTS, NUM_POSTS} + ) + _, _, channel := SetupBenchmark() + + testPoster := NewAutoPostCreator(Client, channel.Id) + posts, valid := testPoster.CreateTestPosts(NUM_POSTS_RANGE) + if valid == false { + b.Fatal("Unable to create test posts") + } + + // Benchmark Start + b.ResetTimer() + for i := 0; i < b.N; i++ { + for i := range posts { + Client.Must(Client.DeletePost(channel.Id, posts[i].Id)) + } + } + +} |