Skip to content

Instantly share code, notes, and snippets.

@h-bragg
Created May 5, 2017 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h-bragg/4ee7c1600feb176f40aec0f185315f6d to your computer and use it in GitHub Desktop.
Save h-bragg/4ee7c1600feb176f40aec0f185315f6d to your computer and use it in GitHub Desktop.
Benchmark for sending udp messages [test in DogstatsD]
<?php
/**
* This file is part of graze/dog-statsd
*
* Copyright (c) 2017 Nature Delivered Ltd. <https://www.graze.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license https://github.com/graze/dog-statsd/blob/master/LICENSE.md
* @link https://github.com/graze/dog-statsd
*/
namespace Graze\DogStatsD\Test\Benchmark;
use Graze\DogStatsD\Client;
use Graze\DogStatsD\Test\TestCase;
class SendBench
{
/**
* @var resource|null
*/
private $socket = null;
/**
* @Iterations(100)
* @Revs(50)
*/
public function benchPersistentConnection()
{
$message = "some stuff in here";
if (is_null($this->socket)) {
$this->socket = @fsockopen('udp://127.0.0.1', 8125, $errno, $errstr);
}
@fwrite($this->socket, $message);
}
/**
* @Iterations(100)
* @Revs(50)
*/
public function benchNewConnection()
{
$message = "some stuff in here";
$socket = @fsockopen('udp://127.0.0.1', 8125, $errno, $errstr);
fwrite($socket, $message);
fclose($socket);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment