I agree with Stefan. Easy way is too server intensive and your hosting company will kick you out at no time if you use such an algorithm.
However if any hackers take it, here is an algorithm which requires more hacking but is performance friendly: (Don't look at me, I don't have time, sorry!)
You can add a new field to smilie table named "usagecount" and populate this field with a script once. Then you can hack newreply.php, newthread.php, editpost.php and private.php and apply a hack which updates this field on the fly whenever a new post is sent by counting the smilies.
Then queries and smilies stats can easily be compiled without any server load.