本文共 1870 字,大约阅读时间需要 6 分钟。
by Rina Artstain
通过丽娜·阿斯特斯坦
I once had a web siteon which one could searchfor all sorts of things(as long as they’re strings)
我曾经有一个网站,可以搜索各种各样的东西(只要它们是字符串)
The items had titlesand content and moreso the search used a regexto help you explore
这些项目具有标题和内容,而且搜索使用正则表达式来帮助您探索
We had an ideawe gave it a trylet’s help you find morewe’ll add synonyms galore
我们有一个主意,我们给了它一个尝试的帮助,您可以找到更多我们将添加同义词galore
We tacked on those wordsto the end of the regexand straight to production(we didn’t have stress tests)
我们将这些字词加到正则表达式的末尾,然后直接投入生产(我们没有压力测试)
And lo and beholdthe site all but crashedso many timeoutswe all were abashed
瞧,这个站点几乎崩溃了,所以超时了,我们都震惊了
The change was revertedand there we sat hurtedtrying to thinkwhat brought us to this brink
更改被撤消,我们坐在那里痛苦地想着是什么使我们陷入了这种边缘
We researched those regexesand guess what we found:you should compile them firstif you want them around
我们研究了这些正则表达式并猜测我们发现了什么:如果需要它们,请先编译它们
So try that we didand it didn’t workthe site was still slowwe hoped it’s a quirk
所以尝试我们做到了,但没有成功,网站仍然很慢,我们希望这是一个怪癖
We tried many thingswe were all stressinguntil we decidedit’s time to start testing!
我们尝试了很多我们都在强调的事情,直到我们决定是时候开始测试了!
We drew up some schemesfor searching multiple wordsand what a surprisewe saw with our eyes
我们制定了一些搜索多个单词的方案,以及我们眼中看到的惊喜
String.Find()was 1000 times fasterthan all of those regexeswhich caused the disaster
String.Find()比引起灾难的所有正则表达式快1000倍
We learned our lessonI hope you did tooregexes are evilexcept for a few
我们吸取了教训我希望你也做过正则表达式是邪恶的,除了一些
If your regex is simplejust put it awayyou’re probably wastingyour time anyway
如果您的正则表达式简单易用,那么您可能正在浪费您的时间
All of us knowthe truth’s where it’s atin most of the casesYOU DON’T NEED A REGEX FOR THAT
我们所有人都知道,在大多数情况下,真相就在这里。您不需要正则表达式
P.S.Please excuse my bad rhymes and rhythm, I get paid to write software. Not poetry.
PS请原谅我不好的节奏和节奏,写软件我得到报酬。 不是诗歌。
翻译自:
转载地址:http://xdewd.baihongyu.com/