views:

166

answers:

2

I'm consuming a web service using a stand-alone VBScript.

The web service returns to me a list of jobs, which I need to loop through and add to a SQL database.

I can either

  1. Run through the nodelist, reading the data and actioning the SQL insert in the loop.
    or
  2. Run through the nodelist building a recordset, then run through the recordset actioning the SQL inserts.

Option 1 has speed on its side, but option 2 just seems... cleaner somehow.

A: 

Option 2 is faster under load, option 1 is faster to code. Do you want to spend time making it fancy & fast, or just bust it out clean & working?

Set it in its own function so it's insular, and if you need the speed later it's an easy refactor. Then you can get on to coding other things. Write it right, optimize it later.

Autocracy
Can you expand on how option 2 is faster at runtime? I'm looping through the data twice that way - surely that has a significant overhead?
ChristianLinnell
Why is option 2 faster under load?
Andomar
Yes, I can. SQL inserts put much less load on the database when they are batched.
Autocracy
+1 Makes sense, though you could batch the SQL without an intermediate recordset!
Andomar
Which is what I'll do. Thanks guys.
ChristianLinnell
+1  A: 

Some computer scientist by the name of Donald Knuth once said,

Premature optimization is the root of all evil (or at least most of it) in programming.

You receive the answer from the web service as an HTTP stream, and unless you're doing something very special, your code won't get control until the entire answer has been received. So storing it in an intermediate recordset won't win any time. Even so, it won't be big overhead.

So go for whatever you're confident you can code without error.

Andomar
True - I hadn't thought about the fact my XMLDOM object is already an iteratable set of records (for my purposes anyway).
ChristianLinnell