protected function execute(InputInterface $input, OutputInterface $output) { $stopwatch = new \Symfony\Component\Stopwatch\Stopwatch(); $stopwatch->start('DbClean'); $pdo = $this->getService('sugarcrm.pdo'); $this->getService('sugarcrm.entrypoint'); // go to sugar folder to make sure we are in the right folder if ($input->getOption('remove-deleted') === false && $input->getOption('clean-cstm') === false && $input->getOption('clean-history') === false && $input->getOption('clean-activities') === false) { $msg = 'You need to set at least --remove-deleted or --clean-xxxxxx'; throw new \InvalidArgumentException($msg); } // Make sure that we don't anonymize production if ($this->askConfirmation($input, $output) === false) { return; } $tables = $input->getOption('table'); if (empty($tables)) { $tables = $this->getNonAuditAndCacheTables($pdo); } foreach ($tables as $table) { if ($this->tableExists($pdo, $table) === false) { $output->writeln("<error>{$table} does not exist</error>"); continue; } $this->cleanDeletedAndCustomTable($input, $output, $pdo, $table); } $tables = $input->getOption('table'); $auditJobQueueAndTrackerTables = $this->getAuditJobQueueAndTrackersTables($input, $pdo); foreach ($auditJobQueueAndTrackerTables as $table) { if (!empty($tables) && in_array($table, $tables) || empty($tables)) { $pdo->query("TRUNCATE TABLE `{$table}`"); $output->writeln("<info>Removed everything from {$table}</info>"); } } $tables = $input->getOption('table'); $activitiesTables = $this->getActivitiesTables($input, $pdo); foreach ($activitiesTables as $table) { if (!empty($tables) && in_array($table, $tables) || empty($tables)) { $pdo->query("TRUNCATE TABLE `{$table}`"); $output->writeln("<info>Removed everything from {$table}</info>"); } } // Get memory and execution time information $event = $stopwatch->stop('DbClean'); $memory = round($event->getMemory() / 1024 / 1024, 2); $time = round($event->getDuration() / 1000, 2); $time = $time > 180 ? round($time / 60, 2) . 'mins' : "{$time} sec"; // Final message $output->writeln(PHP_EOL . "<comment>Done in {$time} (consuming {$memory}Mb)</comment>"); }
<?php require __DIR__ . '/../../vendor/autoload.php'; $userAgents = array('Mozilla/5.0 (Windows NT 6.1; rv:20.0) Gecko/20100101 Firefox/20.0 IceDragon/20.0.1.14'); shuffle($userAgents); $stopwatch = new \Symfony\Component\Stopwatch\Stopwatch(); $stopwatch->start('benchmark'); $factory = new \DeviceDetectorIO\DeviceDetector\Factory\DeviceUserAgentFactory(); foreach ($userAgents as $userAgent) { dump($factory->getDevice($userAgent)); } $event = $stopwatch->stop('benchmark'); printf("Benchmark results for 1 useragents:\n"); printf("Duration %s milliseconds.\n", $event->getDuration()); printf("Memory %s bytes.\n", $event->getMemory());
<?php require_once __DIR__ . '/vendor/autoload.php'; $watch = new \Symfony\Component\Stopwatch\Stopwatch(); define('ITERATIONS', 10000); $results = []; /** * Using pecl-uuid by itself */ $watch->start('pecl'); for ($i = 0; $i < ITERATIONS; ++$i) { $x = uuid_create(UUID_TYPE_TIME); } $results['pecl'] = $watch->stop('pecl'); /** * Using the older Rhumsaa\Uuid version of the library */ $watch->start('rhumsaa'); for ($i = 0; $i < ITERATIONS; ++$i) { $x = (string) \Rhumsaa\Uuid\Uuid::uuid1(); } $results['rhumsaa'] = $watch->stop('rhumsaa'); /** * Using Ramsey\Uuid with default time generator */ $watch->start('ramsey-default'); for ($i = 0; $i < ITERATIONS; ++$i) { $x = (string) \Ramsey\Uuid\Uuid::uuid1(); } $results['ramsey-default'] = $watch->stop('ramsey-default'); /**
protected function execute(InputInterface $input, OutputInterface $output) { $stopwatch = new \Symfony\Component\Stopwatch\Stopwatch(); $stopwatch->start('Anon'); $pdo = $this->getService('sugarcrm.pdo'); $this->getService('sugarcrm.entrypoint'); // go to sugar folder to make sure we are in the right folder // Make sure that we don't anonymize production if ($input->getOption('force') === true && $this->askConfirmation($input, $output) === false) { return; } // Anon READER $reader = new \Inet\Neuralyzer\Configuration\Reader($input->getOption('file')); // Now work on the DB $anon = new \Inet\Neuralyzer\Anonymizer\DB($pdo); $anon->setConfiguration($reader); // Get tables $tables = $input->getOption('table'); if (empty($tables)) { $tables = $reader->getEntities(); } $pretend = $input->getOption('force') === true ? false : true; foreach ($tables as $table) { // Do I need to clean the table ? $this->cleanTable($input, $output, $pdo, $table); // Start to work $result = $pdo->query($sql = "SELECT COUNT(1) FROM {$table}"); if ($result === false) { throw new \PDOException("Error in SQL: {$sql}, are you sure {$table} exists ?"); } $data = $result->fetchAll(\PDO::FETCH_COLUMN); $total = (int) $data[0]; if ($total === 0) { $output->writeln("<info>{$table} is empty</info>" . PHP_EOL); continue; } $bar = new ProgressBar($output, $total); $bar->setRedrawFrequency($total > 100 ? 100 : 0); $output->writeln("<info>Anonymizing {$table}</info>"); $queries = $anon->processEntity($table, function () use($bar) { $bar->advance(); }, $pretend, $input->getOption('sql')); $output->writeln(PHP_EOL); if ($input->getOption('sql')) { $output->writeln('<comment>Queries:</comment>'); $output->writeln(implode(PHP_EOL, $queries)); $output->writeln(PHP_EOL); } } $this->cleanAuditAndTrackers($output, $pdo); // Get memory and execution time information $event = $stopwatch->stop('Anon'); $memory = round($event->getMemory() / 1024 / 1024, 2); $time = round($event->getDuration() / 1000, 2); $time = $time > 180 ? round($time / 60, 2) . 'mins' : "{$time} sec"; // Final message $output->writeln(PHP_EOL . "<comment>Done in {$time} (consuming {$memory}Mb)</comment>"); $db = $this->getDb($pdo); if ($input->getOption('force') === true) { $output->writeln(PHP_EOL . '<comment>To export the db run: </comment>'); $output->writeln(" mysqldump --skip-lock-tables {$db} | bzip2 > {$db}." . date('Ymd-Hi') . '.sql.bz2'); } else { $output->writeln(PHP_EOL . "<error>The anonymization didn't run. Use --force to run it.</error>"); } }
<?php require_once __DIR__ . '/vendor/autoload.php'; $watch = new \Symfony\Component\Stopwatch\Stopwatch(); define('ITERATIONS', 10000); $results = []; $watch->start('pecl'); for ($i = 0; $i < ITERATIONS; ++$i) { $x = uuid_create(UUID_TYPE_RANDOM); } $results['pecl'] = $watch->stop('pecl'); $watch->start('rhumsaa'); for ($i = 0; $i < ITERATIONS; ++$i) { $x = (string) \Rhumsaa\Uuid\Uuid::uuid4(); } $results['rhumsaa'] = $watch->stop('rhumsaa'); $watch->start('ramsey-pecl'); for ($i = 0; $i < ITERATIONS; ++$i) { $x = (string) \Ramsey\Uuid\Uuid::uuid4(); } $results['ramsey-pecl'] = $watch->stop('ramsey-pecl'); $watch->start('ramsey-nopecl'); for ($i = 0; $i < ITERATIONS; ++$i) { \Ramsey\Uuid\Uuid::setFactory(new \Ramsey\Uuid\UuidFactory()); $x = (string) \Ramsey\Uuid\Uuid::uuid4(); } $results['ramsey-nopecl'] = $watch->stop('ramsey-nopecl'); $watch->start('ramsey-randomlib'); for ($i = 0; $i < ITERATIONS; ++$i) { $uuidFactory = new \Ramsey\Uuid\UuidFactory(); // Using low-strength generator by default
<?php require_once __DIR__ . '/vendor/autoload.php'; use GraphAware\Reco4PHP\Demo\Github\RecommendationEngine; use GraphAware\Reco4PHP\RecommenderService; $rs = RecommenderService::create("http://localhost:7474"); $rs->registerRecommendationEngine(new RecommendationEngine()); $stopwatch = new \Symfony\Component\Stopwatch\Stopwatch(); $input = $rs->findInputBy('User', 'login', 'jakzal'); $engine = $rs->getRecommender("github_who_to_follow"); $stopwatch->start('reco'); $recommendations = $engine->recommend($input); $e = $stopwatch->stop('reco'); //echo $recommendations->size() . ' found in ' . $e->getDuration() . 'ms' .PHP_EOL; foreach ($recommendations->getItems(10) as $reco) { echo $reco->item()->get('login') . PHP_EOL; echo $reco->totalScore() . PHP_EOL; foreach ($reco->getScores() as $name => $score) { echo "\t" . $name . ':' . $score->score() . PHP_EOL; } }
<?php require_once __DIR__ . '/vendor/autoload.php'; $watch = new \Symfony\Component\Stopwatch\Stopwatch(); define('ITERATIONS', 10000); $results = []; /** * Using pecl-uuid by itself */ $watch->start('pecl'); for ($i = 0; $i < ITERATIONS; ++$i) { $x = uuid_create(UUID_TYPE_RANDOM); } $results['pecl'] = $watch->stop('pecl'); /** * Using the older Rhumsaa\Uuid version of the library */ $watch->start('rhumsaa-openssl'); for ($i = 0; $i < ITERATIONS; ++$i) { $x = (string) \Rhumsaa\Uuid\Uuid::uuid4(); } $results['rhumsaa-openssl'] = $watch->stop('rhumsaa-openssl'); /** * Using the older Rhumsaa\Uuid version of the library without OpenSSL */ $watch->start('rhumsaa-mtrand'); \Rhumsaa\Uuid\Uuid::$forceNoOpensslRandomPseudoBytes = true; for ($i = 0; $i < ITERATIONS; ++$i) { $x = (string) \Rhumsaa\Uuid\Uuid::uuid4(); } $results['rhumsaa-mtrand'] = $watch->stop('rhumsaa-mtrand');