summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/test/benchmark/BulkMemoryUsageTest.php
blob: 23e6521f3e20849858aab55577e0d4cd84812eb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php

use Elastica\Client;
use Elastica\Document;

class BulkMemoryUsageTest extends \PHPUnit_Framework_TestCase
{

    /**
     * Some memory usage stats
     *
     * Really simple and quite stupid ...
     */
    public function testServersArray()
    {
        $client = new Client();
        $index = $client->getIndex('test');
        $index->create(array(), true);
        $type = $index->getType('test');

        $data = array(
            'text1' => 'Very long text for a string',
            'text2' => 'But this is not very long',
            'text3' => 'random or not random?',
        );

        $startMemory = memory_get_usage();

        for ($n = 1; $n < 10; $n++) {
            $docs = array();

            for ($i = 1; $i <= 3000; $i++) {
                $docs[] = new Document(uniqid(), $data);
            }

            $type->addDocuments($docs);
            $docs = array();
        }

        unset($docs);

        $endMemory = memory_get_usage();

        $this->assertLessThan(1.2, $endMemory/$startMemory);
    }
}