Ensure that mouse lock works correctly on Chrome ASH in Windows 8.
[chromium-blink-merge.git] / net / websockets / websocket_frame_perftest.cc
blob11fe5afab2a3ca1c3167656874a42e4a4848b8a3
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.
5 #include "net/websockets/websocket_frame.h"
7 #include <algorithm>
8 #include <vector>
10 #include "base/macros.h"
11 #include "base/test/perf_time_logger.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace net {
16 namespace {
18 const int kIterations = 100000;
19 const int kLongPayloadSize = 1 << 16;
20 const char kMaskingKey[] = "\xFE\xED\xBE\xEF";
22 COMPILE_ASSERT(arraysize(kMaskingKey) ==
23 WebSocketFrameHeader::kMaskingKeyLength + 1,
24 incorrect_masking_key_size);
26 class WebSocketFrameTestMaskBenchmark : public ::testing::Test {
27 protected:
28 void Benchmark(const char* const name,
29 const char* const payload,
30 size_t size) {
31 std::vector<char> scratch(payload, payload + size);
32 WebSocketMaskingKey masking_key;
33 std::copy(kMaskingKey,
34 kMaskingKey + WebSocketFrameHeader::kMaskingKeyLength,
35 masking_key.key);
36 base::PerfTimeLogger timer(name);
37 for (int x = 0; x < kIterations; ++x) {
38 MaskWebSocketFramePayload(
39 masking_key, x % size, &scratch.front(), scratch.size());
41 timer.Done();
45 TEST_F(WebSocketFrameTestMaskBenchmark, BenchmarkMaskShortPayload) {
46 static const char kShortPayload[] = "Short Payload";
47 Benchmark(
48 "Frame_mask_short_payload", kShortPayload, arraysize(kShortPayload));
51 TEST_F(WebSocketFrameTestMaskBenchmark, BenchmarkMaskLongPayload) {
52 std::vector<char> payload(kLongPayloadSize, 'a');
53 Benchmark("Frame_mask_long_payload", &payload.front(), payload.size());
56 } // namespace
58 } // namespace net