2021-12-17 08:04:34 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
2022-06-21 11:57:17 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2021-12-17 08:04:34 +01:00
|
|
|
*/
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-12-17 08:04:34 +01:00
|
|
|
namespace Tests\Unit;
|
|
|
|
|
|
|
|
use App\Models\Currency;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
class RedisVsDatabaseTest extends TestCase
|
|
|
|
{
|
2022-06-21 12:00:57 +02:00
|
|
|
protected function setUp() :void
|
2021-12-17 08:04:34 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
// $this->markTestSkipped('Skip test no company gateways installed');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRedisSpeed()
|
|
|
|
{
|
2024-06-21 02:40:51 +02:00
|
|
|
app('currencies');
|
|
|
|
|
2024-06-21 02:43:52 +02:00
|
|
|
$start = microtime(true);
|
|
|
|
|
2021-12-17 08:04:34 +01:00
|
|
|
$currencies = Cache::get('currencies');
|
|
|
|
|
2024-06-21 02:40:51 +02:00
|
|
|
$currencies->first(function ($item) {
|
2021-12-17 08:04:34 +01:00
|
|
|
return $item->id == 17;
|
2024-06-21 02:40:51 +02:00
|
|
|
});
|
2021-12-17 08:04:34 +01:00
|
|
|
|
2021-12-17 08:57:26 +01:00
|
|
|
nlog(microtime(true) - $start);
|
2021-12-17 08:04:34 +01:00
|
|
|
|
|
|
|
$this->assertTrue(true);
|
|
|
|
// nlog($total_time);
|
2022-06-21 11:57:17 +02:00
|
|
|
//0.0012960433959961
|
2021-12-17 08:04:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDbSpeed()
|
|
|
|
{
|
2022-06-21 11:57:17 +02:00
|
|
|
$start = microtime(true);
|
2021-12-17 08:04:34 +01:00
|
|
|
|
|
|
|
$currency = Currency::find(17);
|
|
|
|
|
2021-12-17 08:57:26 +01:00
|
|
|
nlog(microtime(true) - $start);
|
2021-12-17 08:04:34 +01:00
|
|
|
|
|
|
|
$this->assertTrue(true);
|
|
|
|
// nlog($total_time);
|
2022-06-21 11:57:17 +02:00
|
|
|
// 0.006152868270874
|
2021-12-17 08:04:34 +01:00
|
|
|
}
|
|
|
|
}
|