sample/Application/EncodeSamples.php
/**
     * Run performance test for many times for small nested resources.
     *
     * @param int $iterations
     *
     * @return array
     */
Run performance test for many times for small nested resources.
@param int $iterations

@return array
Run performance test for many times for small nested resources . @param int $iterations @return array
public function runPerformanceTestForSmallNestedResources(int $iterations): array
    {
        $closure = function () use ($iterations) {
            $encoder = Encoder::instance([
                Author::class  => AuthorSchema::class,
                Comment::class => CommentSchema::class,
                Post::class    => PostSchema::class,
                Site::class    => SiteSchema::class
            ]);
            for ($index = 0; $index < $iterations; ++$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]);
                $encoder
                    ->withLinks([Link::SELF => new Link(false,'http://example.com/sites/1?' . $rand, false)])
                    ->withMeta(['some' => ['meta' => 'information' . $rand]])
                    ->withIncludedPaths(['posts.author'])
                    ->withFieldSets(['sites' => ['name'], 'people' => ['first_name']])
                    ->encodeData($site);
            }
        };
        $timeSpent = 0.0;
        $bytesUsed = 0;
        $this->getTime($closure, $timeSpent, $bytesUsed);
        return [$timeSpent, $bytesUsed];
    }
public function runPerformanceTestForSmallNestedResources ( int $ iterations ) : array { $ closure = function ( ) use ( $ iterations ) { $ encoder = Encoder :: instance ( [ Author :: class => AuthorSchema :: class , Comment :: class => CommentSchema :: class , Post :: class => PostSchema :: class , Site :: class => SiteSchema :: class ] ) ; for ( $ index = 0 ; $ index < $ iterations ; ++ $ 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 ] ) ; $ encoder -> withLinks ( [ Link :: SELF => new Link ( false , 'http://example.com/sites/1?' . $ rand , false ) ] ) -> withMeta ( [ 'some' => [ 'meta' => 'information' . $ rand ] ] ) -> withIncludedPaths ( [ 'posts.author' ] ) -> withFieldSets ( [ 'sites' => [ 'name' ] , 'people' => [ 'first_name' ] ] ) -> encodeData ( $ site ) ; } } ; $ timeSpent = 0.0 ; $ bytesUsed = 0 ; $ this -> getTime ( $ closure , $ timeSpent , $ bytesUsed ) ; return [ $ timeSpent , $ bytesUsed ] ; }
Run performance test for many times for small nested resources.
Run performance test for many times for small nested resources .