diff --git a/tests/perf/BigQuery/Benchmark.php b/tests/perf/BigQuery/Benchmark.php new file mode 100644 index 000000000000..56dabd11bb69 --- /dev/null +++ b/tests/perf/BigQuery/Benchmark.php @@ -0,0 +1,58 @@ +"); + 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"; +} diff --git a/tests/perf/BigQuery/README.md b/tests/perf/BigQuery/README.md new file mode 100644 index 000000000000..f23539e1835a --- /dev/null +++ b/tests/perf/BigQuery/README.md @@ -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. diff --git a/tests/perf/BigQuery/queries.json b/tests/perf/BigQuery/queries.json new file mode 100644 index 000000000000..13fed38b52b3 --- /dev/null +++ b/tests/perf/BigQuery/queries.json @@ -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" +]