Skip to content

Conversation

@norberttech
Copy link
Member

Change Log

Added

  • Blackfire PHP SDK to tools

Fixed

  • Optimized BinaryBufferWriter

Changed

Removed

Deprecated

Security


Description

The goal of adding backfire SDK to tools is to let run local benchmarks with some pieces of the code excluded, like in the following example:

<?php

use Faker\Factory;
use Flow\Parquet\Consts;
use Flow\Parquet\Option;
use Flow\Parquet\Options;
use Flow\Parquet\ParquetFile\Schema;
use Flow\Parquet\ParquetFile\Schema\FlatColumn;
use Flow\Parquet\ParquetFile\Schema\ListElement;
use Flow\Parquet\ParquetFile\Schema\MapKey;
use Flow\Parquet\ParquetFile\Schema\MapValue;
use Flow\Parquet\ParquetFile\Schema\NestedColumn;
use Flow\Parquet\Writer;

include __DIR__ . '/../vendor/autoload.php';
include __DIR__ . '/../tools/blackfire/vendor/autoload.php';


$blackfire = new \Blackfire\Client();
$probe = $blackfire->createProbe(null, false);

// Disable profiling for the irrelevant parts of the code
$probe->disable();
$faker = Factory::create();

$inputValues = \array_map(function($i) use ($faker) {
    return []; // some heavy random data generator
}, \range(0, 100_000));

$path = __DIR__ . '/flow.parquet';

if (\file_exists($path)) {
    unlink($path);
}


// Actual profiling starts here
$probe->enable();

const MB_SIZE_BYTES = 1024 * 1024;

$writer = new Writer(
    Options::default()
        ->set(Option::ROW_GROUP_SIZE_BYTES, MB_SIZE_BYTES * 2)
        ->set(Option::PAGE_SIZE_BYTES, 1024)
);

$schema = Schema::with(
    FlatColumn::boolean('boolean'),
    FlatColumn::int32('int32'),
    FlatColumn::int64('int64'),
    FlatColumn::float('float'),
    FlatColumn::double('double'),
    FlatColumn::decimal('decimal'),
    FlatColumn::string('string'),
    FlatColumn::date('date'),
    FlatColumn::dateTime('datetime'),
    NestedColumn::list('list_of_datetimes', ListElement::dateTime()),
    NestedColumn::map('map_of_ints', MapKey::string(), MapValue::int32()),
    NestedColumn::list('list_of_strings', ListElement::string()),
    NestedColumn::struct('struct_flat', [
        FlatColumn::int32('id'),
        FlatColumn::string('name')
    ]),
);

$writer->write($path, $schema, $inputValues);

$profile = $blackfire->endProbe($probe);
// Profiling ends here
var_dump($profile->getUrl());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant