sample/Application/EncodeSamples.php
/**
     * Run performance test one time for big collection of resources.
     *
     * @param int $numberOfItems
     *
     * @return array
     */
Run performance test one time for big collection of resources.

@return array
Run performance test one time for big collection of resources . @return array
public function runPerformanceTestForBigCollection(int $numberOfItems): array
    {
        $closure = function() use ($numberOfItems) {
            $sites = [];
            for ($index = 0; $index < $numberOfItems; ++$index) {
                $rand = rand();
                $author   = Author::instance('123', 'John' . $rand, 'Dow' . $rand);
                $comments = [
                    Comment::instance('456', 'Included objects work as easy as basic ones' . $rand, $author),
                    Comment::instance('789', 'Let\'s try!' . $rand, $author),
                ];
                $post = Post::instance('321', 'Included objects' . $rand, 'Yes, it is supported', $author, $comments);
                $site = Site::instance('1', 'JSON API Samples' . $rand, [$post]);
                $sites[] = $site;
            }
            $encoder = Encoder::instance([
                Author::class  => AuthorSchema::class,
                Comment::class => CommentSchema::class,
                Post::class    => PostSchema::class,
                Site::class    => SiteSchema::class
            ]);
            $encoder
                ->withIncludedPaths(['posts.author', 'posts.comments'])
                ->withFieldSets(['sites' => ['name'], 'people' => ['first_name']])
                ->encodeData($sites);
        };
        $timeSpent = 0.0;
        $bytesUsed = 0;
        $this->getTime($closure, $timeSpent, $bytesUsed);
        return [$timeSpent, $bytesUsed];
    }
public function runPerformanceTestForBigCollection ( int $ numberOfItems ) : array { $ closure = function ( ) use ( $ numberOfItems ) { $ sites = [ ] ; for ( $ index = 0 ; $ index < $ numberOfItems ; ++ $ index ) { $ rand = rand ( ) ; $ author = Author :: instance ( '123' , 'John' . $ rand , 'Dow' . $ rand ) ; $ comments = [ Comment :: instance ( '456' , 'Included objects work as easy as basic ones' . $ rand , $ author ) , Comment :: instance ( '789' , 'Let\'s try!' . $ rand , $ author ) , ] ; $ post = Post :: instance ( '321' , 'Included objects' . $ rand , 'Yes, it is supported' , $ author , $ comments ) ; $ site = Site :: instance ( '1' , 'JSON API Samples' . $ rand , [ $ post ] ) ; $ sites [ ] = $ site ; } $ encoder = Encoder :: instance ( [ Author :: class => AuthorSchema :: class , Comment :: class => CommentSchema :: class , Post :: class => PostSchema :: class , Site :: class => SiteSchema :: class ] ) ; $ encoder -> withIncludedPaths ( [ 'posts.author' , 'posts.comments' ] ) -> withFieldSets ( [ 'sites' => [ 'name' ] , 'people' => [ 'first_name' ] ] ) -> encodeData ( $ sites ) ; } ; $ timeSpent = 0.0 ; $ bytesUsed = 0 ; $ this -> getTime ( $ closure , $ timeSpent , $ bytesUsed ) ; return [ $ timeSpent , $ bytesUsed ] ; }
Run performance test one time for big collection of resources.
Run performance test one time for big collection of resources .