What is the best choice to create a node through code? The scenario goes this way, I have a node type which has lot of Taxonomy term fields in it. It does also have other fields like text, date etc but 90% of it is a taxonomy field. I am aware that a node can be created programatically in two ways,


node_save() -  Creating a node object and saving it

$node =  new stdClass();

$node-&gt;type = 'article';

$node-&gt;field_term[LANGUAGE_NONE][0]['tid'] = 3128 // term id of the term

node_save($node);

Form submit - creating a form array and submitting using drupal_form_submit

$node[field_first]['und'] =&gt; chennai;

$node[field_second]['und'] =&gt; "iphone5";

$node['type'] = 'article'; 

$form_state['values'] = $node;

$form_state['values']['op'] = t('Save');

drupal_form_submit($node_type . '_node_form', $form_state, (object)$node);


with $node having the POST values.


Advantage of using form submit method is Drupal will take care of creating new terms in vocabulary (I am supposed to get more new terms). Form submit can follow form validations which is needed for creating a node.

Is there any method to create nodes faster in to Drupal system which supposed to get more terms in it?

If there is no other method than the above mentioned, what is the best one?
The safest method is to use drupal_form_submit(). If you take at look at the services module it does the same thing. Form validation should be important if you are creating nodes programmatically. Are you importing or creating multiple nodes at once? If this is the case and you are concerned about performance you can use Drupal's batch api or queue. Batch is great if you need user feedback but if you are creating nodes on cron and don't require a ui with feedback then queue is the way to go. In both cases they take care of memory management for you. 

I wouldn't be to concerned about how long it takes to create one node as that is how long it would take with the ui. Unless the reason you are doing it through codes is to increase creation times.