Home > Backend Development > PHP Tutorial > ThinkPHP Db and model performance evaluation

ThinkPHP Db and model performance evaluation

*文
Release: 2023-03-18 08:20:01
Original
3326 people have browsed it

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(&#39;end&#39;);
        echo Debug::getRangeTime(&#39;begin&#39;,&#39;end&#39;).&#39;s&#39;;
Copy after login


The time is 5.182297s (average of three times, basically the same)
Code to operate using model

        set_time_limit(0);
        Debug::remark(&#39;begin&#39;);
        $user = model(&#39;user&#39;);
        for ($i=0; $i < 10000; $i++) { 
            $user->get(1);
        }
        Debug::remark(&#39;end&#39;);
        echo Debug::getRangeTime(&#39;begin&#39;,&#39;end&#39;).&#39;s&#39;;
Copy after login

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:

#TP5 Model Function Summary

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template