Benchmark


    × Bunları biliyor muydunuz?
"ZN Framework düzenlenebilir dizin yapısı ile kendi kod çatınızı oluşturmanıza imkan veren dünyadaki tek kod çatısıdır."


(ZN >= 1.0.0)

Benchmark kütüphanesi, yazacağınız sistemin veya kodların performansını test etmek amacıyla oluşturulmuştur.

 

 

# Kurulum


ZN dağıtımları için kurulum gerekmez.

↓ composer require znframework/package-comparison

 

 

# Yöntemler


1.0.0 void start(string $test)
1.0.0 void end(string $test)
4.0.1 this run(callable $callback)
5.0.0 this cycle(int $count = 1, callable $callback)
1.0.0 float elapsedTime(string $result, int $decimal = 4)
1.0.0 int memoryUsage(bool $realMemory = false)
1.0.0 int maxMemoryUsage(bool $realMemory = false)
2.0.0 int calculatedMemory(string $result)
2.0.0 array usedFiles(string $result = NULL)
2.0.0 int usedFileCount(string $result = NULL)

 

 

# Start (ZN >= 1.0.0)


Testi başlatır.

Parametreler

string $test Test adı.
return void

Kullanımı

Benchmark::start('test');
# your codes
Benchmark::end('test');

output(Benchmark::elapsedTime('test'));

 

 

# End (ZN >= 1.0.0)


Testi bitirir.

Parametreler

string $test Test adı.
return void

Kullanımı

Benchmark::start('test');
     # your codes
Benchmark::end('test');

Benchmark::start('test1');
     # your codes
Benchmark::end('test1');

output(Benchmark::elapsedTime('test'));
output(Benchmark::elapsedTime('test1'));

 

 

# Run (ZN >= 4.0.1)


Benchmark::start() ve Benchmark::end() yöntemlerinin yaptığı işlemi yapar.

Parametreler

callable $callback Performansı ölçülecek kodlar.
return this

Opsiyonel Yöntemler

this result()

Kullanımı

File: Controller/TestController.php
<?php namespace Project\Controllers;

use Benchmark, DB;

class TestController extends Controller
{
    public function main(string $params = NULL)
    {
        $bench = Benchmark::run(function()
        {
            DB::get('users')->result();
        });

        output($bench->result());
    }
}
elapsedTime => double 0.0162 ( length = 6 )
calculatedMemory => double 407640 ( length = 6 )
usedFileCount => integer 18 ( length = 2 )
usedFiles => object
(
        129 => string 'Internal/Libraries/Database/DBInternalDB.php' ( length = 107 )
        130 => string 'Internal/Libraries/Database/DBInternalDB.php' ( length = 72 )
        131 => string 'Internal/Libraries/Database/Connection.php' ( length = 69 )
        132 => string 'Internal/Libraries/Database/ConnectionInterface.php' ( length = 78 )
        133 => string 'Internal/Libraries/Database/Database/DBTraitsVariableTypesTrait.php' ( length = 87 )
        134 => string 'Internal/Libraries/Database/Database/DBTraitsStatementsTrait.php' ( length = 84 )
        135 => string 'Internal/Libraries/Database/DBTraitsFunctionsTrait.php' ( length = 83 )
        136 => string 'Internal/Libraries/Database/DBInternalDBInterface.php' ( length = 81 )
        137 => string 'Projects/Example/Config/Database.php' ( length = 63 )
        138 => string 'Projects/Example/Resources/Statics/Internal/Libraries/Individual/Structures/Support/InternalSupport.php' ( length = 129 )
        139 => string 'Internal/Libraries/IndividualStructures/Support/InternalSupport.php' ( length = 94 )
        140 => string 'Internal/Libraries/Requirements/Controllers/CallController.php' ( length = 89 )
        141 => string 'Internal/Libraries/IndividualStructures/Support/InternalSupportInterface.php' ( length = 103 )
        142 => string 'Internal/Libraries/Database/DriversPDOPDO.php' ( length = 74 )
        143 => string 'Internal/Libraries/Database/DriverConnectionMappingAbstract.php' ( length = 90 )
        144 => string 'Internal/Libraries/Database/Properties.php' ( length = 69 )
        145 => string 'Internal/Libraries/Database/DriversPDODriversMySQL.php' ( length = 84 )
        146 => string 'Internal/Libraries/Database/DriversPDODriverInterface.php' ( length = 86 )

 

 

# Cycle (ZN >= 5.0.0)


Benchmark::run() kullanımı gibidir. Farklı olarak bir kodu belli sayıda çalıştırmak için kullanılır. Bir nevi çalıştırılacak kodu döngüye sokarak test eder.

Parametreler

int $count = 1 Kodların kaç kez çalıştırılacağı.
callable $callback Performansı ölçülecek kodlar.
return this

Opsiyonel Yöntemler

this result()

Kullanımı

File: Controller/TestController.php
<?php namespace Project\Controllers;

use Benchmark, DB;

class TestController extends Controller
{
    public function main(string $params = NULL)
    {
        $bench = Benchmark::cycle(1000, function()
        {
            DB::get('users')->result();
        });

        output($bench->result());
    }
}

Yukarıdaki örnekte kodun 1000 kez çalıştırılması sağlanmıştır.

 

 

# ElapsedTime (ZN >= 1.0.0)


Test sonunda geçen süreyi öğrenmek için kullanılır.

Parametreler

string $test Test adı.
int $decimal = 4 Ondalıklı rakam adeti.
return float

Kullanımlar

\Output::writeLine( Benchmark::elapsedTime('test', 5) );
\Output::writeLine( Benchmark::elapsedTime('test1', 6) );
0.87320
0.429302

 

 

# MemoryUsage (ZN >= 1.0.0)


PHP kodlarının sistemde kaç byte yer kapladığını öğrenmek için kullanılır.

Parametreler

bool $realMemory = false Gerçek hafıza miktarı hesaplansın mı?
return float

Kullanımlar

echo Converter::byte( Benchmark::memoryUsage() );
876.9 KB

 

 

# MaxMemoryUsage (ZN >= 1.0.0)


PHP kodlarına ayrılan maksimum bellek miktarını öğrenmek için kullanılır.

Parametreler

bool $realMemory = false Gerçek hafıza miktarı hesaplansın mı?
return float

Kullanımlar

echo Converter::byte( Benchmark::maxMemoryUsage() );
1 MB

 

 

# CalculatedMemory (ZN >= 2.0.0)


Bir PHP kodunun bellekte ne kadar yer kapladığını hesaplamak için kullanılır.

Parametreler

string $test Test adı.
return float

Kullanımlar

echo Benchmark::calculatedMemory('test'); 
echo Benchmark::calculatedMemory('test1');
13882
12231
Uyarı: Bu yöntemin hesaplamaları %100 doğru sonuç vermeyebilir.

 

 

# UsedFiles (ZN >= 2.0.0)


Testte kullanılan dosyaların listesini dizi türünde çıktılar.

Parametreler

string $test Test adı.
return array

Kullanımlar

output( Benchmark::usedFiles('test1') );

 

 

# UsedFileCount (ZN >= 2.0.0)


Testte kullanılan dosyaların sayısını çıktılar.

Parametreler

string $test Test adı.
return int

Kullanımlar

echo Benchmark::usedFileCount('test1');
10