Exemplo n.º 1
0
 public static function getInstance()
 {
     if (self::$instance == NULL) {
         self::$instance = new Timer();
     }
     return self::$instance;
 }
Exemplo n.º 2
0
 /**
  * Lazy loading of Timer class instance.
  *
  * @return Timer
  */
 public static function instance()
 {
     if (self::$instance === null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
<?php

require 'sharedance.class.php';
require 'timer.php';
$timer =& Timer::instance();
$timer->start('connect');
$cache = new Sharedance();
$cache->addServer(new SharedanceServer('127.0.0.1', 8989));
$cache->addServer(new SharedanceServer('127.0.0.1', 8990));
$cache->addServer(new SharedanceServer('127.0.0.1', 8991));
$timer->stop('connect');
$timer->start('run');
for ($i = 0; $i < 10000; $i++) {
    if ($i % 500 == 0) {
        echo '.';
    }
    $key = md5(microtime() . mt_rand(1, 1000));
    $cache->set($key, 'Some text about the number ' . $i);
    $cache->get($key);
}
$timer->stop('run');
echo "\n";
$timer->show();
Exemplo n.º 4
0
<?php

function __autoload($name)
{
    require_once "classes/{$name}.php";
}
$t = Timer::instance();
$t->newTimePoint('Begin of requuest');
VehicleFactory::create(VehicleFactory::TYPE_CAR)->move();
echo '<br />';
$t->newTimePoint('After "Car" creation');
VehicleFactory::create(VehicleFactory::TYPE_PLANE)->move();
echo '<br />';
$t->newTimePoint('After "Plane" creation');
$bookAdapter = new BookAdapter(new Book('Nikolay D.', 'It woluld be nice to have my own book :]'));
echo "{$bookAdapter->getAuthorAndTitle()}<br />";
$t->newTimePoint('Prepare library.');
$booksDb = array(new Book('A 1', 'T 1'), 1, new Book('A 1', 'T 2'), 2, new Book('A 2', 'T 1'), 3, new Book('A 3', 'T 1'), 4, new Book('A 3', 'T 2'), 5);
$library = new Library('FMI Library');
for ($i = 0; $i < count($booksDb); $i += 2) {
    $library->addBook($booksDb[$i], $booksDb[$i + 1]);
}
echo "Library content: total => {$library->getBooksCount()}, distinct => {$library->getDistinctBooksCount()}<br />";
$book = $booksDb[0];
$t->newTimePoint('Library - prepared, testing proxy implementation.');
echo 'Proxy test...<br />';
$proxy = new LibraryProxy($library);
if ($proxy->hasQuantityFor($book)) {
}
echo "{$book} is in the library.<br />";
$ticket = $proxy->lendBook($book);