mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
DEV: Apply syntax_tree formatting to script/*
This commit is contained in:
5
script/benchmarks/cache/bench.rb
vendored
5
script/benchmarks/cache/bench.rb
vendored
@ -1,10 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'benchmark/ips'
|
||||
require File.expand_path('../../../../config/environment', __FILE__)
|
||||
require "benchmark/ips"
|
||||
require File.expand_path("../../../../config/environment", __FILE__)
|
||||
|
||||
Benchmark.ips do |x|
|
||||
|
||||
x.report("redis setex string") do |times|
|
||||
while times > 0
|
||||
Discourse.redis.setex("test_key", 60, "test")
|
||||
|
@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'benchmark/ips'
|
||||
require File.expand_path('../../../../config/environment', __FILE__)
|
||||
require "benchmark/ips"
|
||||
require File.expand_path("../../../../config/environment", __FILE__)
|
||||
|
||||
# set any flags here
|
||||
# MiniRacer::Platform.set_flags! :noturbo
|
||||
@ -10,7 +10,7 @@ tests = [
|
||||
["tiny post", "**hello**"],
|
||||
["giant post", File.read("giant_post.md")],
|
||||
["most features", File.read("most_features.md")],
|
||||
["lots of mentions", File.read("lots_of_mentions.md")]
|
||||
["lots of mentions", File.read("lots_of_mentions.md")],
|
||||
]
|
||||
|
||||
PrettyText.cook("")
|
||||
@ -31,9 +31,7 @@ PrettyText.v8.eval("window.commonmark = window.markdownit('commonmark')")
|
||||
Benchmark.ips do |x|
|
||||
[true, false].each do |sanitize|
|
||||
tests.each do |test, text|
|
||||
x.report("#{test} sanitize: #{sanitize}") do
|
||||
PrettyText.markdown(text, sanitize: sanitize)
|
||||
end
|
||||
x.report("#{test} sanitize: #{sanitize}") { PrettyText.markdown(text, sanitize: sanitize) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'memory_profiler'
|
||||
require 'benchmark/ips'
|
||||
require "memory_profiler"
|
||||
require "benchmark/ips"
|
||||
|
||||
ENV["RAILS_ENV"] = "production"
|
||||
|
||||
@ -14,12 +14,10 @@ def req
|
||||
"timings[1]" => "1001",
|
||||
"timings[2]" => "1001",
|
||||
"timings[3]" => "1001",
|
||||
"topic_id" => "490310"
|
||||
"topic_id" => "490310",
|
||||
}
|
||||
|
||||
data = data.map do |k, v|
|
||||
"#{CGI.escape(k)}=#{v}"
|
||||
end.join("&")
|
||||
data = data.map { |k, v| "#{CGI.escape(k)}=#{v}" }.join("&")
|
||||
|
||||
{
|
||||
"REQUEST_METHOD" => "POST",
|
||||
@ -33,7 +31,7 @@ def req
|
||||
"HTTP_COOKIE" => "_t=#{_t}",
|
||||
"rack.input" => StringIO.new(data),
|
||||
"rack.version" => [1, 2],
|
||||
"rack.url_scheme" => "http"
|
||||
"rack.url_scheme" => "http",
|
||||
}
|
||||
end
|
||||
|
||||
@ -45,11 +43,7 @@ end
|
||||
exit
|
||||
#
|
||||
#
|
||||
StackProf.run(mode: :wall, out: 'report.dump') do
|
||||
1000.times do
|
||||
Rails.application.call(req)
|
||||
end
|
||||
end
|
||||
StackProf.run(mode: :wall, out: "report.dump") { 1000.times { Rails.application.call(req) } }
|
||||
#
|
||||
# MemoryProfiler.start
|
||||
# Rails.application.call(req)
|
||||
|
@ -1,37 +1,32 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'benchmark/ips'
|
||||
require File.expand_path('../../../../config/environment', __FILE__)
|
||||
require "benchmark/ips"
|
||||
require File.expand_path("../../../../config/environment", __FILE__)
|
||||
|
||||
# Put pre conditions here
|
||||
# Used db but it's OK in the most cases
|
||||
|
||||
# build the cache
|
||||
SiteSetting.title = SecureRandom.hex
|
||||
SiteSetting.default_locale = SiteSetting.default_locale == 'en' ? 'zh_CN' : 'en'
|
||||
SiteSetting.default_locale = SiteSetting.default_locale == "en" ? "zh_CN" : "en"
|
||||
SiteSetting.refresh!
|
||||
|
||||
tests = [
|
||||
["current cache", lambda do
|
||||
SiteSetting.title
|
||||
SiteSetting.enable_discourse_connect
|
||||
end
|
||||
[
|
||||
"current cache",
|
||||
lambda do
|
||||
SiteSetting.title
|
||||
SiteSetting.enable_discourse_connect
|
||||
end,
|
||||
],
|
||||
["change default locale with current cache refreshed", lambda do
|
||||
SiteSetting.default_locale = SiteSetting.default_locale == 'en' ? 'zh_CN' : 'en'
|
||||
end
|
||||
],
|
||||
["change site setting", lambda do
|
||||
SiteSetting.title = SecureRandom.hex
|
||||
end
|
||||
[
|
||||
"change default locale with current cache refreshed",
|
||||
lambda { SiteSetting.default_locale = SiteSetting.default_locale == "en" ? "zh_CN" : "en" },
|
||||
],
|
||||
["change site setting", lambda { SiteSetting.title = SecureRandom.hex }],
|
||||
]
|
||||
|
||||
Benchmark.ips do |x|
|
||||
tests.each do |test, proc|
|
||||
x.report(test, proc)
|
||||
end
|
||||
end
|
||||
Benchmark.ips { |x| tests.each { |test, proc| x.report(test, proc) } }
|
||||
|
||||
# 2017-08-02 - Erick's Site Setting change
|
||||
|
||||
|
@ -1,34 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'ruby-prof'
|
||||
require "ruby-prof"
|
||||
|
||||
def profile(&blk)
|
||||
result = RubyProf.profile(&blk)
|
||||
printer = RubyProf::GraphHtmlPrinter.new(result)
|
||||
printer.print(STDOUT)
|
||||
end
|
||||
profile { '' } # loading profiler dependency
|
||||
profile { "" } # loading profiler dependency
|
||||
|
||||
require File.expand_path('../../../../config/environment', __FILE__)
|
||||
require File.expand_path("../../../../config/environment", __FILE__)
|
||||
|
||||
# warming up
|
||||
SiteSetting.title
|
||||
SiteSetting.enable_discourse_connect
|
||||
SiteSetting.default_locale = SiteSetting.default_locale == 'en' ? 'zh_CN' : 'en'
|
||||
SiteSetting.default_locale = SiteSetting.default_locale == "en" ? "zh_CN" : "en"
|
||||
SiteSetting.title = SecureRandom.hex
|
||||
|
||||
profile do
|
||||
SiteSetting.title
|
||||
end
|
||||
profile { SiteSetting.title }
|
||||
|
||||
profile do
|
||||
SiteSetting.enable_discourse_connect
|
||||
end
|
||||
profile { SiteSetting.enable_discourse_connect }
|
||||
|
||||
profile do
|
||||
SiteSetting.default_locale = SiteSetting.default_locale == 'en' ? 'zh_CN' : 'en'
|
||||
end
|
||||
profile { SiteSetting.default_locale = SiteSetting.default_locale == "en" ? "zh_CN" : "en" }
|
||||
|
||||
profile do
|
||||
SiteSetting.title = SecureRandom.hex
|
||||
end
|
||||
profile { SiteSetting.title = SecureRandom.hex }
|
||||
|
Reference in New Issue
Block a user