Is custom coding faster than Rules when reacting on user creation? I'm granting an avatar to the users on my website, based on their gender (cf. this answer). I've been able to achieve this both programatically and with 3 Rules.

This is my custom module:

function custom_user_presave (&amp;$edit, $account) {
    $tid = $edit['field_geslacht']['und'][0]['target_id'];
    if ($account-&gt;is_new OR !isset ($account-&gt;roles[3])) {
        $avatar = taxonomy_term_load($tid);
        }
        else {
            $avatar = taxonomy_term_load(8);
        }
    $edit['field_avatar']['und'][0]['fid'] = $avatar-&gt;field_avatar['und'][0]['fid'];
    $edit['field_avatar']['und'][0]['width'] = $avatar-&gt;field_avatar['und'][0]['width'];
    $edit['field_avatar']['und'][0]['height'] = $avatar-&gt;field_avatar['und'][0]['height'];
    $edit['field_avatar']['und'][0]['alt'] = $avatar-&gt;field_avatar['und'][0]['alt'];
    $edit['field_avatar']['und'][0]['title'] = $avatar-&gt;field_avatar['und'][0]['title'];
}


This is one of my exported rules (the second only differs in the action part and the third one checks whether the user has a certain role):

{ "rules_avatar" : {
    "LABEL" : "Avatar",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "avatar" ],
    "REQUIRES" : [ "rules" ],
    "ON" : { "user_insert" : [], "user_update" : [] },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "account" ], "field" : "field_geslacht" } },
      { "data_is" : { "data" : [ "account:field-geslacht" ], "value" : "Man" } }
    ],
    "DO" : [
      { "data_set" : { "data" : [ "account:field-avatar:file" ], "value" : "35" } }
    ]
  }
}


I'm wondering which method is the fastest/most efficient. Can you help me?
I wouldn't focus too much on speed in situations like this because it's extensibility you will care about as the site grows in function. While your custom code is probably "faster" it's not the measure you should be deciding by since it'll be nanoseconds you're talking about and any good caching strategy will nullify most of that concern.

But to answer your question, your code would likely be faster especially if you're not defining as many hooks as the Rules module.

However, I'd advise using rules for the following reasons.


Rules are exportable
Rules are integrated with all the "big" modules out there.
Never program something you can borrow. :)


Hope this helps.