php - performance: store a large mysql result in class vars VS result array -
hej folks,
i wondering faster. suggest have big database table 50 columns , class handles these columns.
the class constructor loads fields - , here starts question.
is useful store every column in own class variable or juts unperformant? in case have array, e.g. $result keys table columns.
or irrelevant?
i tried write benchmark have vserver test results not clear.
is 1 time function stores values in class vars faster searching whole array every 'get' method?
thanks in advance :)
p.s. php 5
i think answer question "it doesn't matter".
in terms of application performance, code you're talking - iterating on loop in memory 50 times , manipulating data in memory, retrieving class data, or retrieving data associative array - blazingly fast. fast it's impossible measure differences under normal circumstances. in order notice difference between employee::$id, employee::$name
vs employee::$result['id'], employee::$result['name']
you'd have dealing extreme circumstances - $result array of millions of columns, instance. see this benchmark.
on other hand, design point of view, there trade-offs - mapping result class variables, can hide business logic, , create consistent interface. instance, if employee class needs calculate annual_salary based on database field monthly_salary, can create class variable called "annual_salary", , client code consistent - it's employee::annual_salary
, employee::monthly_salary
, not employee::result['monthly_salary']
, employee::annual_salary
.
Comments
Post a Comment