| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/websockets/websocket_frame.h" | 5 #include "net/websockets/websocket_frame.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 void Benchmark(const char* const payload, size_t size) { | 360 void Benchmark(const char* const payload, size_t size) { |
| 361 std::vector<char> scratch(payload, payload + size); | 361 std::vector<char> scratch(payload, payload + size); |
| 362 static const char kMaskingKey[] = "\xFE\xED\xBE\xEF"; | 362 static const char kMaskingKey[] = "\xFE\xED\xBE\xEF"; |
| 363 COMPILE_ASSERT( | 363 COMPILE_ASSERT( |
| 364 arraysize(kMaskingKey) == WebSocketFrameHeader::kMaskingKeyLength + 1, | 364 arraysize(kMaskingKey) == WebSocketFrameHeader::kMaskingKeyLength + 1, |
| 365 incorrect_masking_key_size); | 365 incorrect_masking_key_size); |
| 366 WebSocketMaskingKey masking_key; | 366 WebSocketMaskingKey masking_key; |
| 367 std::copy(kMaskingKey, | 367 std::copy(kMaskingKey, |
| 368 kMaskingKey + WebSocketFrameHeader::kMaskingKeyLength, | 368 kMaskingKey + WebSocketFrameHeader::kMaskingKeyLength, |
| 369 masking_key.key); | 369 masking_key.key); |
| 370 LOG(INFO) << "Benchmarking MaskWebSocketFramePayload() for " << iterations_ | 370 VLOG(0) << "Benchmarking MaskWebSocketFramePayload() for " << iterations_ |
| 371 << " iterations"; | 371 << " iterations"; |
| 372 using base::TimeTicks; | 372 using base::TimeTicks; |
| 373 TimeTicks start = TimeTicks::HighResNow(); | 373 TimeTicks start = TimeTicks::HighResNow(); |
| 374 for (int x = 0; x < iterations_; ++x) { | 374 for (int x = 0; x < iterations_; ++x) { |
| 375 MaskWebSocketFramePayload( | 375 MaskWebSocketFramePayload( |
| 376 masking_key, x % size, &scratch.front(), scratch.size()); | 376 masking_key, x % size, &scratch.front(), scratch.size()); |
| 377 } | 377 } |
| 378 double total_time_ms = | 378 double total_time_ms = |
| 379 1000 * (TimeTicks::HighResNow() - start).InMillisecondsF() / | 379 1000 * (TimeTicks::HighResNow() - start).InMillisecondsF() / |
| 380 iterations_; | 380 iterations_; |
| 381 LOG(INFO) << "Payload size " << size | 381 VLOG(0) << "Payload size " << size |
| 382 << base::StringPrintf(" took %.03f microseconds per iteration", | 382 << base::StringPrintf(" took %.03f microseconds per iteration", |
| 383 total_time_ms); | 383 total_time_ms); |
| 384 } | 384 } |
| 385 | 385 |
| 386 private: | 386 private: |
| 387 int iterations_; | 387 int iterations_; |
| 388 | 388 |
| 389 DISALLOW_COPY_AND_ASSIGN(WebSocketFrameTestMaskBenchmark); | 389 DISALLOW_COPY_AND_ASSIGN(WebSocketFrameTestMaskBenchmark); |
| 390 }; | 390 }; |
| 391 | 391 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 // Check that opcodes with the 4 bit set return false | 453 // Check that opcodes with the 4 bit set return false |
| 454 EXPECT_FALSE(Frame::IsKnownControlOpCode(0x6)); | 454 EXPECT_FALSE(Frame::IsKnownControlOpCode(0x6)); |
| 455 EXPECT_FALSE(Frame::IsKnownControlOpCode(0xF)); | 455 EXPECT_FALSE(Frame::IsKnownControlOpCode(0xF)); |
| 456 | 456 |
| 457 // Check that out-of-range opcodes return false | 457 // Check that out-of-range opcodes return false |
| 458 EXPECT_FALSE(Frame::IsKnownControlOpCode(-1)); | 458 EXPECT_FALSE(Frame::IsKnownControlOpCode(-1)); |
| 459 EXPECT_FALSE(Frame::IsKnownControlOpCode(0xFF)); | 459 EXPECT_FALSE(Frame::IsKnownControlOpCode(0xFF)); |
| 460 } | 460 } |
| 461 | 461 |
| 462 } // namespace net | 462 } // namespace net |
| OLD | NEW |