Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions tests/perf/BigQuery/Benchmark.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* Copyright 2017 Google Inc. All Rights Reserved.
*
* 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.
*/

require 'vendor/autoload.php';

use Google\Cloud\BigQuery\BigQueryClient;

if (count($argv) < 2) {
print("usage: php {$argv[0]} <queries.json>");
exit(1);
}

$requests = json_decode(file_get_contents($argv[1]));

$bigQuery = new BigQueryClient();

foreach ($requests as $request) {
$start = microtime(true);
$queryResults = $bigQuery->runQuery($request, [
'useLegacySql' => false,
]);

while (!$queryResults->isComplete()) {
sleep(1);
$queryResults->reload();
}

$rows = 0;
$cols = 0;
$firstByteDur = 0;

foreach ($queryResults->rows() as $row) {
$rows++;
if ($cols == 0) {
$firstByteDur = microtime(true) - $start;
$cols = count($row);
} elseif ($cols != count($row)) {
throw new Exception("expected $cols cols, found " . count($row));
}
}

$totalDur = microtime(true)-$start;
print "query $request: $rows rows, $cols cols, first byte $firstByteDur, total $totalDur\n";
}
10 changes: 10 additions & 0 deletions tests/perf/BigQuery/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# BigQuery Benchmark
This directory contains benchmarks for BigQuery client.

## Usage
From the `google-cloud-php` directory, set up by running `composer install`.

`php tests/perf/BigQuery/Benchmark.php tests/perf/BigQuery/queries.json`

BigQuery service caches requests so the benchmark should be run
at least twice, disregarding the first result.
10 changes: 10 additions & 0 deletions tests/perf/BigQuery/queries.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
"SELECT * FROM `nyc-tlc.yellow.trips` LIMIT 10000",
"SELECT * FROM `nyc-tlc.yellow.trips` LIMIT 100000",
"SELECT * FROM `nyc-tlc.yellow.trips` LIMIT 1000000",
"SELECT title FROM `bigquery-public-data.samples.wikipedia` ORDER BY title LIMIT 1000",
"SELECT title, id, timestamp, contributor_ip FROM `bigquery-public-data.samples.wikipedia` WHERE title like 'Blo%' ORDER BY id",
"SELECT * FROM `bigquery-public-data.baseball.games_post_wide` ORDER BY gameId",
"SELECT * FROM `bigquery-public-data.samples.github_nested` WHERE repository.has_downloads ORDER BY repository.created_at LIMIT 10000",
"SELECT repo_name, path FROM `bigquery-public-data.github_repos.files` WHERE path LIKE '%.java' ORDER BY id LIMIT 1000000"
]