OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "net/websockets/websocket_frame.h" | |
6 | |
7 #include <algorithm> | |
8 #include <vector> | |
9 | |
10 #include "base/macros.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/test/perf_time_logger.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 | |
15 namespace net { | |
16 | |
17 namespace { | |
18 | |
19 const int kIterations = 100000; | |
20 const int kLongPayloadSize = 1 << 16; | |
21 const char kMaskingKey[] = "\xFE\xED\xBE\xEF"; | |
22 | |
23 COMPILE_ASSERT(arraysize(kMaskingKey) == | |
24 WebSocketFrameHeader::kMaskingKeyLength + 1, | |
25 incorrect_masking_key_size); | |
26 | |
27 class WebSocketFrameTestMaskBenchmark : public ::testing::Test { | |
28 protected: | |
29 void Benchmark(const char* const name, | |
30 const char* const payload, | |
31 size_t size) { | |
32 std::vector<char> scratch(payload, payload + size); | |
33 WebSocketMaskingKey masking_key; | |
34 std::copy(kMaskingKey, | |
35 kMaskingKey + WebSocketFrameHeader::kMaskingKeyLength, | |
36 masking_key.key); | |
37 base::PerfTimeLogger timer(name); | |
38 for (int x = 0; x < kIterations; ++x) { | |
39 MaskWebSocketFramePayload( | |
40 masking_key, x % size, &scratch.front(), scratch.size()); | |
41 } | |
42 timer.Done(); | |
43 } | |
44 }; | |
45 | |
46 TEST_F(WebSocketFrameTestMaskBenchmark, BenchmarkMaskShortPayload) { | |
47 static const char kShortPayload[] = "Short Payload"; | |
48 Benchmark( | |
49 "Frame_mask_short_payload", kShortPayload, arraysize(kShortPayload)); | |
50 } | |
51 | |
52 TEST_F(WebSocketFrameTestMaskBenchmark, BenchmarkMaskLongPayload) { | |
53 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.
| |
54 std::fill(payload.get(), payload.get() + kLongPayloadSize, 'a'); | |
55 Benchmark("Frame_mask_long_payload", payload.get(), kLongPayloadSize); | |
56 } | |
57 | |
58 } // namespace | |
59 | |
60 } // namespace net | |
OLD | NEW |