我应该先构建记录集还是只插入数据?
我正在使用独立 VBScript 来使用 Web 服务。
Web 服务返回给我一个作业列表,我需要循环遍历该作业列表并将其添加到 SQL 数据库中。
我可以
- 运行节点列表、读取数据并在循环中执行 SQL 插入操作。
或者 - 运行构建记录集的节点列表,然后运行执行 SQL 插入操作的记录集。
选项 1 速度快,但选项 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
- Run through the nodelist, reading the data and actioning the SQL insert in the loop.
or - 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一位名叫唐纳德·高德纳 (Donald Knuth) 的计算机科学家曾经说过:
您以 HTTP 流的形式从 Web 服务接收答案,除非您正在做一些非常特殊的事情,否则在收到整个答案之前,您的代码将无法获得控制权。 因此,将其存储在中间记录集中永远不会获胜。 即便如此,开销也不会很大。
因此,只要您有信心可以毫无错误地编写代码,就可以选择。
Some computer scientist by the name of Donald Knuth once said,
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.
选项 2 在负载下速度更快,选项 1 编码速度更快。 您想花时间让它变得花哨吗? 快,或者干脆把它清理干净& 在职的?
将其设置在自己的函数中,这样它就变得孤立了,如果您稍后需要速度,则可以轻松重构。 然后你就可以继续编码其他事情了。 写对了,以后再优化。
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.