Home >Backend Development >PHP Tutorial >ThinkPHP Db and model performance evaluation
ThinkPHP provides a more convenient model. Let's take a look at how the performance compares with Db.
Code to operate using Db
set_time_limit(0); Debug::remark('begin'); $user = Db::name('user'); for ($i=0; $i < 10000; $i++) { $user->find(1); } Debug::remark('end'); echo Debug::getRangeTime('begin','end').'s';
The time is 5.182297s (average of three times, basically the same)
Code to operate using model
set_time_limit(0); Debug::remark('begin'); $user = model('user'); for ($i=0; $i < 10000; $i++) { $user->get(1); } Debug::remark('end'); echo Debug::getRangeTime('begin','end').'s';
The time is 5.683325s (the average of three times, basically the same)
The difference between 10,000 operations is only 0.5 seconds, which is really negligible.
Related reading:
thinkphp Database configuration issues
Resource sharing about TP5.0 MVC introductory video
The above is the detailed content of ThinkPHP Db and model performance evaluation. For more information, please follow other related articles on the PHP Chinese website!