История изменений
Исправление lbvf50txt, (текущая версия) :
Я на питоне лет 10-15 пишу и хорошо знаком с его производительностью.
Про Python я рассказывать не буду, но вот у Ruby с Go в однопотоке на практических задачах может быть вполне сопоставимая скорость. Тут обработка строк при помощи Regex.
- Sprip HTML:
331.474 ms Ruby
195.624 ms Go
- Remove
-
:102.34 ms Ruby
588.275 ms Go
# Ruby
# Strip HTML 331.474 ms
# Remove `-` 102.34 ms
run
texts = contents.map{|html|
html
.gsub(/<!--.*?-->/m, '')
.gsub(/ /, ' ')
.gsub(/<\/?[^>]+>/, '')
}
stop("Strip HTML")
run
texts.map!{|v| v.gsub(/(\s)-{2}(\s)/, '\1-\2')}
stop("Remove `-`")
// Golang (LLM translation from the Ruby source)
// Strip HTML 195.624 ms
// Remove `-` 588.275 ms
run()
commentRe := regexp.MustCompile(`(?s)<!--.*?-->`)
tagRe := regexp.MustCompile(`</?[^>]+>`)
for i, html := range contents {
t := commentRe.ReplaceAllString(html, "")
t = strings.ReplaceAll(t, " ", " ")
t = tagRe.ReplaceAllString(t, "")
contents[i] = t
}
stop("Strip HTML")
run()
dashRe := regexp.MustCompile(`(\s)-{2}(\s)`)
for i, v := range contents {
contents[i] = dashRe.ReplaceAllString(v, "$1-$2")
}
stop("Remove `-`")
Исходная версия lbvf50txt, :
Я на питоне лет 10-15 пишу и хорошо знаком с его производительностью.
Про Python я рассказывать не буду, но вот у Ruby с Go в однопотоке на практических задачах может быть вполне сопоставимая скорость. Тут обработка строк при помощи Regex.
- Sprip HTML:
331.474 ms Ruby
195.624 ms Go
- Remove
-
:102.34 ms Ruby
588.275 ms Go
# Ruby
# Strip HTML 331.474 ms
# Remove `-`
run
texts = contents.map{|html|
html
.gsub(/<!--.*?-->/m, '')
.gsub(/ /, ' ')
.gsub(/<\/?[^>]+>/, '')
}
stop("Strip HTML")
run
texts.map!{|v| v.gsub(/(\s)-{2}(\s)/, '\1-\2')}
stop("Remove `-`")
// Golang (LLM translation from the Ruby source)
// Strip HTML 195.624 ms
// Remove `-` 588.275 ms
run()
commentRe := regexp.MustCompile(`(?s)<!--.*?-->`)
tagRe := regexp.MustCompile(`</?[^>]+>`)
for i, html := range contents {
t := commentRe.ReplaceAllString(html, "")
t = strings.ReplaceAll(t, " ", " ")
t = tagRe.ReplaceAllString(t, "")
contents[i] = t
}
stop("Strip HTML")
run()
dashRe := regexp.MustCompile(`(\s)-{2}(\s)`)
for i, v := range contents {
contents[i] = dashRe.ReplaceAllString(v, "$1-$2")
}
stop("Remove `-`")