Chromium Code Reviews| Index: net/websockets/websocket_frame_perftest.cc |
| diff --git a/net/websockets/websocket_frame_perftest.cc b/net/websockets/websocket_frame_perftest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..44bcd1855248f56f6d9d6f4048dc21e9c91ce02d |
| --- /dev/null |
| +++ b/net/websockets/websocket_frame_perftest.cc |
| @@ -0,0 +1,60 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "net/websockets/websocket_frame.h" |
| + |
| +#include <algorithm> |
| +#include <vector> |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/test/perf_time_logger.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace net { |
| + |
| +namespace { |
| + |
| +const int kIterations = 100000; |
| +const int kLongPayloadSize = 1 << 16; |
| +const char kMaskingKey[] = "\xFE\xED\xBE\xEF"; |
| + |
| +COMPILE_ASSERT(arraysize(kMaskingKey) == |
| + WebSocketFrameHeader::kMaskingKeyLength + 1, |
| + incorrect_masking_key_size); |
| + |
| +class WebSocketFrameTestMaskBenchmark : public ::testing::Test { |
| + protected: |
| + void Benchmark(const char* const name, |
| + const char* const payload, |
| + size_t size) { |
| + std::vector<char> scratch(payload, payload + size); |
| + WebSocketMaskingKey masking_key; |
| + std::copy(kMaskingKey, |
| + kMaskingKey + WebSocketFrameHeader::kMaskingKeyLength, |
| + masking_key.key); |
| + base::PerfTimeLogger timer(name); |
| + for (int x = 0; x < kIterations; ++x) { |
| + MaskWebSocketFramePayload( |
| + masking_key, x % size, &scratch.front(), scratch.size()); |
| + } |
| + timer.Done(); |
| + } |
| +}; |
| + |
| +TEST_F(WebSocketFrameTestMaskBenchmark, BenchmarkMaskShortPayload) { |
| + static const char kShortPayload[] = "Short Payload"; |
| + Benchmark( |
| + "Frame_mask_short_payload", kShortPayload, arraysize(kShortPayload)); |
| +} |
| + |
| +TEST_F(WebSocketFrameTestMaskBenchmark, BenchmarkMaskLongPayload) { |
| + scoped_ptr<char[]> payload(new char[kLongPayloadSize]); |
|
yhirano
2014/08/27 07:22:33
How about using std::vector<char> payload(kLongPay
Adam Rice
2014/08/27 07:39:41
Done.
|
| + std::fill(payload.get(), payload.get() + kLongPayloadSize, 'a'); |
| + Benchmark("Frame_mask_long_payload", payload.get(), kLongPayloadSize); |
| +} |
| + |
| +} // namespace |
| + |
| +} // namespace net |