ChannelCredentials::createInsecure()]); $a = 123; $b = 456; $addreq = new AddRequest(); $addreq->setA($a); $addreq->setB($b); $c = $client->Add($addreq)->wait()[0]->getC(); echo $c . "\r\n"; $s = 'ABC'; $dupreq = new DupRequest(); $dupreq->setS($s); $s2 = $client->Dup($dupreq)->wait()[0]->getS2(); echo $s2 . "\r\n"; $d = new Data(['iv' => 123, 'sv' => 'ABC']); $d2 = $client->process($d)->wait()[0]; echo sprintf('%d %s', $d2->getIv(), $d2->getSv()) . "\r\n"; $client->close(); } function testInstantiation($host, $port) { $client1 = new TestClient($host . ':' . $port, ['credentials' => ChannelCredentials::createInsecure()]); for($i = 0; $i < 2; $i++) { $n = $client1->GetCounter(new GPBEmpty())->wait()[0]->getCounter(); echo $n . "\r\n"; } $client1->close(); $client2 = new TestClient($host . ':' . $port, ['credentials' => ChannelCredentials::createInsecure()]); for($i = 0; $i < 2; $i++) { $n = $client2->GetCounter(new GPBEmpty())->wait()[0]->getCounter(); echo $n . "\r\n"; } $client2->close(); } define('REP', 100000); function testPerformance($host, $port) { $client = new TestClient($host . ':' . $port, ['credentials' => ChannelCredentials::createInsecure()]); $t1 = microtime(true); for($i = 0; $i < REP; $i++) { $dummy = $client->Noop(new GPBEmpty())->wait()[0]; } $t2 = microtime(true); echo sprintf('%d requests per second', REP / ($t2 - $t1)) . "\r\n"; $client->close(); } function testStream($host, $port) { $client = new TestClient($host . ':' . $port, ['credentials' => ChannelCredentials::createInsecure()]); $stm = $client->StreamProcess(); for($i = 0; $i < 10; $i++) { $d = new Data(['iv' => $i, 'sv' => chr(65 + $i)]); $stm->write($d); } $stm->writesDone(); while($d2 = $stm->read()) { echo sprintf('%d %s', $d2->getIv(), $d2->getSv()) . "\r\n"; } $client->close(); } function testStreamPerformance($host, $port) { $client = new TestClient($host . ':' . $port, ['credentials' => ChannelCredentials::createInsecure()]); $t1 = microtime(true); $stm = $client->StreamNoop(); for($i = 0; $i < REP; $i++) { $stm->write(new GPBEmpty()); } $stm->writesDone(); while($d2 = $stm->read()) { ; } $t2 = microtime(true); echo sprintf('%d requests per second', REP / ($t2 - $t1)) . "\r\n"; $client->close(); } function test($lbl, $host, $port) { echo $lbl . ":\r\n"; testFunctional($host, $port); testInstantiation($host, $port); testPerformance($host, $port); testStream($host, $port); testStreamPerformance($host, $port); } define('JAVA_HOST', 'localhost'); define('JAVA_PORT', 12345); define('DOTNET_HOST', 'localhost'); define('DOTNET_PORT', 12346); define('DOTNET2_HOST', 'localhost'); define('DOTNET2_PORT', 12347); define('PYTHON_HOST', 'localhost'); define('PYTHON_PORT', 12348); define('CPP_HOST', 'localhost'); define('CPP_PORT', 12349); test('Java', JAVA_HOST, JAVA_PORT); test('.NET', DOTNET_HOST, DOTNET_PORT); test('.NET', DOTNET2_HOST, DOTNET2_PORT); test('Python', PYTHON_HOST, PYTHON_PORT); test('C++', CPP_HOST, CPP_PORT); ?>