Benchmark
KUT 1.0’da desteklenir Benchmark kütüphanesi, yazacağınız sistemin veya kodların performansını test etmek amacıyla oluşturulmuştur. # Kurulum KUT Framework içinde ayrıca paket kurulumu gerek…
KUT 1.0’da desteklenir
Benchmark kütüphanesi, yazacağınız sistemin veya kodların performansını test etmek amacıyla oluşturulmuştur.
Kurulum
Bu bileşen KUT ile birlikte gelir; ayrıca kurulum gerektirmez.
↓ Paket KUT ile birlikte gelir.
Yöntemler
| KUT 1.0 | void | start(string $test) |
| KUT 1.0 | void | end(string $test) |
| KUT 1.0 | this | run(callable $callback) |
| KUT 1.0 | this | cycle(int $count = 1, callable $callback) |
| KUT 1.0 | float | elapsedTime(string $result, int $decimal = [[4]]) |
| KUT 1.0 | int | memoryUsage(bool $realMemory = [[false]]) |
| KUT 1.0 | int | maxMemoryUsage(bool $realMemory = [[false]]) |
| KUT 1.0 | int | calculatedMemory(string $result) |
| KUT 1.0 | array | usedFiles(string $result = [[NULL]]) |
| KUT 1.0 | int | usedFileCount(string $result = [[NULL]]) |
# Start KUT 1.0’da desteklenir
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 KUT 1.0’da desteklenir
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 KUT 1.0’da desteklenir
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ı
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());
}
}
calculatedMemory => double 407640 ( length = 6 )
usedFileCount => integer 18 ( length = 2 )
usedFiles => object
(
129 => string 'System/Libraries/Database/DBInternalDB.php' ( length = 107 )
130 => string 'System/Libraries/Database/DBInternalDB.php' ( length = 72 )
131 => string 'System/Libraries/Database/Connection.php' ( length = 69 )
132 => string 'System/Libraries/Database/ConnectionInterface.php' ( length = 78 )
133 => string 'System/Libraries/Database/Database/DBTraitsVariableTypesTrait.php' ( length = 87 )
134 => string 'System/Libraries/Database/Database/DBTraitsStatementsTrait.php' ( length = 84 )
135 => string 'System/Libraries/Database/DBTraitsFunctionsTrait.php' ( length = 83 )
136 => string 'System/Libraries/Database/DBInternalDBInterface.php' ( length = 81 )
137 => string 'Projects/Example/Config/Database.php' ( length = 63 )
138 => string 'Projects/Example/Resources/Statics/System/Libraries/Individual/Structures/Support/FacadeSupport.php' ( length = 129 )
139 => string 'System/Libraries/IndividualStructures/Support/FacadeSupport.php' ( length = 94 )
140 => string 'System/Libraries/Requirements/Controllers/CallController.php' ( length = 89 )
141 => string 'System/Libraries/IndividualStructures/Support/FacadeSupportInterface.php' ( length = 103 )
142 => string 'System/Libraries/Database/DriversPDOPDO.php' ( length = 74 )
143 => string 'System/Libraries/Database/DriverConnectionMappingAbstract.php' ( length = 90 )
144 => string 'System/Libraries/Database/Properties.php' ( length = 69 )
145 => string 'System/Libraries/Database/DriversPDODriversMySQL.php' ( length = 84 )
146 => string 'System/Libraries/Database/DriversPDODriverInterface.php' ( length = 86 )
)
# Cycle KUT 1.0’da desteklenir
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ı
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 KUT 1.0’da desteklenir
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.429302
# MemoryUsage KUT 1.0’da desteklenir
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() );
# MaxMemoryUsage KUT 1.0’da desteklenir
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() );
# CalculatedMemory KUT 1.0’da desteklenir
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');
12231
# UsedFiles KUT 1.0’da desteklenir
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 KUT 1.0’da desteklenir
Testte kullanılan dosyaların sayısını çıktılar.
Parametreler
| string | $test | Test adı. |
| return | int | |
Kullanımlar
echo Benchmark::usedFileCount('test1');