Performance Difference with Response

Submitted by pratikbutani - 2 years ago

There are many tricks to return the response in `json`. Actually, if the returned value is an array or instance of "arrayableinterface" or "jsonableinterface" such as eloquent model, you could just return it, it'll be a json, magically. There are following three way i have noticed performance :) Thanks. #KeepSharing

/**
 **  Returning response with Response::json
 **/
 /** Taking Time to Execute: 1649ms **/
$account = Account::all();
return Response::json($account);

/** 
 ** Returning response direct Model using Eloquent
 **/
 /** Taking Time to Execute: 1751ms **/
return Account::all();

/** 
 ** Returning response using json_encode();
 **/
 /** Taking Time to Execute: 2258ms **/
$account = Account::all();
return json_encode($account);

Ads cover the costs of maintaining Laravel-tricks

comments powered by Disqus

Ads cover the costs of maintaining Laravel-tricks