which code has better performance

hi there

which of following codes has better performance?

does these have so much diff?




foreach($model->images as $image){

    $imagine = (new Imagine())->open(Yii::$app->basePath . '/../all_assets/uploads/' . $img->name);

   $imagine->resize($imagine->getSize()->widen(200))->save(Yii::$app->basePath . '/../all_assets/uploads/thumb_' . $img->name);

}# end of "foreach($model->images as $image)"






$obj = new Imagine();                    

foreach($model->images as $image){

   $imagine = $obj->open(Yii::$app->basePath . '/../all_assets/uploads/' . $img->name);

   $imagine->resize($imagine->getSize()->widen(200))->save(Yii::$app->basePath . '/../all_assets/uploads/thumb_' . $img->name);

}# end of "foreach($model->images as $image)"



I bet the second option because of you create Imagine object only once (less memory is used). You have to investigate it by adding profiler, then you will know for sure.

Second should be faster but I can’t tell how much w/o profiling.

In this context (resizing images) it probably doesn’t matter - most of the work is related to the operations on the image.