azure-sdk-for-cpp/sdk/storage/test/blobs/large_scale_test.cpp
JinmingHu 0f37994e44
add perf benchmark code (#319)
* Add multithread perf testcase

* add large scale upload testcase

* Fix compiler error on GCC 9

* Fix failed testcase
2020-07-17 11:16:18 +08:00

62 lines
1.8 KiB
C++

// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include "blobs/blob.hpp"
#include "common/file_io.hpp"
#include "test_base.hpp"
#include <chrono>
namespace Azure { namespace Storage { namespace Test {
TEST(BlobsLargeScaleTest, DISABLED_LargeScaleUpload)
{
const std::string containerName = "large-scale-test";
auto containerClient = Azure::Storage::Blobs::BlobContainerClient::CreateFromConnectionString(
StandardStorageConnectionString(), containerName);
try
{
containerClient.Create();
}
catch (StorageError& e)
{
if (e.StatusCode != Azure::Core::Http::HttpStatusCode::Conflict)
{
throw;
}
}
auto blockBlobClient = Azure::Storage::Blobs::BlockBlobClient::CreateFromConnectionString(
StandardStorageConnectionString(), containerName, "LargeScale" + RandomString());
const std::string sourceFile = "";
std::size_t fileSize = 0;
constexpr std::size_t concurrency = 16;
ASSERT_FALSE(sourceFile.empty());
{
Details::FileReader reader(sourceFile);
fileSize = static_cast<std::size_t>(reader.GetFileSize());
}
Blobs::UploadBlobOptions options;
options.Concurrency = concurrency;
auto timer_start = std::chrono::steady_clock::now();
try
{
auto res = blockBlobClient.UploadFromFile(sourceFile, options);
}
catch (std::exception& e)
{
std::cout << e.what() << std::endl;
}
auto timer_end = std::chrono::steady_clock::now();
double speed = static_cast<double>(fileSize) / 1_MB
/ std::chrono::duration_cast<std::chrono::milliseconds>(timer_end - timer_start).count()
* 1000;
std::cout << "Upload " << static_cast<double>(fileSize) / 1_GB << "GiB, speed " << speed
<< "MiB/s" << std::endl;
}
}}} // namespace Azure::Storage::Test