This repository has been archived by the owner on Apr 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read in file-cache entries all at once, rather than a chunk at a time.
When reading large images a chunk at a time, callgrind indicated a significant amount of time spent appending bytes to a dynamically expanding buffer. Note: this adds a call to fstat so we know the size of the file before we start to read it. Another note: the only way I could find to implement this reading into std::string involved using std::string::resize, which nulls the bytes we are about to write. That seems like a shame but it is what it is :).
- Loading branch information
Showing
6 changed files
with
143 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright 2015 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// Author: jmarantz@google.com (Joshua Marantz) | ||
|
||
#include "base/logging.h" | ||
#include "pagespeed/kernel/base/basictypes.h" | ||
#include "pagespeed/kernel/base/benchmark.h" | ||
#include "pagespeed/kernel/base/google_message_handler.h" | ||
#include "pagespeed/kernel/base/gtest.h" | ||
#include "pagespeed/kernel/base/stdio_file_system.h" | ||
#include "pagespeed/kernel/base/string.h" | ||
#include "pagespeed/kernel/base/string_util.h" | ||
#include "pagespeed/kernel/base/string_writer.h" | ||
|
||
// Running the speed test: | ||
// src/out/Release/mod_pagespeed_speed_test .File | ||
// BM_100kWholeFile 100000 18845 ns/op | ||
// BM_100kStreamingFile 50000 70181 ns/op | ||
// BM_1MWholeFile 10000 122070 ns/op | ||
// BM_1MStreamingFile 2000 760416 ns/op | ||
// | ||
|
||
namespace net_instaweb { | ||
|
||
namespace { | ||
|
||
class FSTester { | ||
public: | ||
explicit FSTester(int size) { | ||
StopBenchmarkTiming(); | ||
GoogleString str; | ||
str.append(size, 'a'); | ||
filename_ = StrCat(GTestTempDir(), "large_file.txt"); | ||
file_system_.WriteFile(filename_.c_str(), str, &handler_); | ||
} | ||
|
||
~FSTester() { | ||
file_system_.RemoveFile(filename_.c_str(), &handler_); | ||
StartBenchmarkTiming(); | ||
} | ||
|
||
void ReadWholeFile(int iters) { | ||
StartBenchmarkTiming(); | ||
for (int i = 0; i < iters; ++i) { | ||
GoogleString buf; | ||
CHECK(file_system_.ReadFile(filename_.c_str(), &buf, &handler_)); | ||
} | ||
StopBenchmarkTiming(); | ||
} | ||
|
||
void StreamingReadFile(int iters) { | ||
StartBenchmarkTiming(); | ||
for (int i = 0; i < iters; ++i) { | ||
GoogleString buf; | ||
StringWriter writer(&buf); | ||
CHECK(file_system_.ReadFile(filename_.c_str(), &writer, &handler_)); | ||
} | ||
StopBenchmarkTiming(); | ||
} | ||
|
||
private: | ||
StdioFileSystem file_system_; | ||
GoogleString filename_; | ||
GoogleMessageHandler handler_; | ||
}; | ||
|
||
static void BM_100kWholeFile(int iters) { | ||
FSTester fs_tester(100000); | ||
fs_tester.ReadWholeFile(iters); | ||
} | ||
BENCHMARK(BM_100kWholeFile); | ||
|
||
static void BM_100kStreamingFile(int iters) { | ||
FSTester fs_tester(100000); | ||
fs_tester.StreamingReadFile(iters); | ||
} | ||
BENCHMARK(BM_100kStreamingFile); | ||
|
||
static void BM_1MWholeFile(int iters) { | ||
FSTester fs_tester(1000000); | ||
fs_tester.ReadWholeFile(iters); | ||
} | ||
BENCHMARK(BM_1MWholeFile); | ||
|
||
static void BM_1MStreamingFile(int iters) { | ||
FSTester fs_tester(1000000); | ||
fs_tester.StreamingReadFile(iters); | ||
} | ||
BENCHMARK(BM_1MStreamingFile); | ||
|
||
} // namespace | ||
|
||
} // namespace net_instaweb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters