This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
total_times = 30000 | |
items1 = [] | |
items2 = [] | |
items3 = [] | |
Benchmark.bm do |x| | |
x.report("include?") { | |
total_times.times do |i| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Before | |
user system total real | |
Index 1,000 items 2.160000 0.820000 2.980000 ( 4.633564) | |
## After (0.9.6) | |
user system total real | |
Index 1,000 items 0.780000 0.070000 0.850000 ( 0.851309) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def api_request(action, params = {}) | |
Rails.logger.info "Started request #{host_root} action: #{action}" | |
# Rails.logger.info " Params: #{params.inspect}" | |
t1 = Time.now | |
n = 0 | |
begin | |
res = Faraday.post do |req| | |
req.url "http://api.kanbox.com" | |
req.body = Kanbox::Param.parse(action, params) | |
req.options[:open_timeout] = 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Calculating ------------------------------------- | |
keys.index 1794 i/100ms | |
has_key? 1822 i/100ms | |
------------------------------------------------- | |
keys.index 4036912.9 (±10.4%) i/s - 8691930 in 2.275054s | |
has_key? 6605458.9 (±9.1%) i/s - 25340376 in 3.878441s | |
Comparison: | |
has_key?: 6605458.9 i/s | |
keys.index: 4036912.9 i/s - 1.64x slower |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task :test_string_freeze_vs_nofreeze do | |
str = "this is a example string" | |
Benchmark.ips do |x| | |
x.report("no_freeze") { | |
str.index("example") | |
} | |
x.report("freeze") { | |
str.index("example".freeze) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Calculating ------------------------------------- | |
str.start_with? 78491 i/100ms | |
str[0] == '/' 66410 i/100ms | |
------------------------------------------------- | |
str.start_with? 3663514.9 (±7.8%) i/s - 18209912 in 5.002869s | |
str[0] == '/' 2905683.6 (±7.6%) i/s - 14477380 in 5.011908s | |
Comparison: | |
str.start_with?: 3663514.9 i/s | |
str[0] == '/': 2905683.6 i/s - 1.26x slower |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
URI_REGEXP = %r{^[-a-z]+://|^(?:cid|data):|^//}i | |
def asset_path(source, options = {}) | |
source = source.to_s | |
return "" unless source.present? | |
return source if source =~ URI_REGEXP | |
tail = source[/([\?#].+)$/] || '' | |
source.chomp!(tail) | |
if extname = compute_asset_extname(source, options) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.xml.bind.DatatypeConverter; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
// 用于将 GPS 的坐标格式转成浮点数 | |
// 如 DMSToDecimal.convert("N 30d17m27.786712646484375s") => 30.282034 | |
public class DMSToDecimal { | |
private static final String REGEXP = "(N|E|W|S)([\\.\\d\\s]+)d([\\.\\d\\s]+)m([\\.\\d\\s]+)s"; | |
private static double dmsToDecimal(String hemisphereOUmeridien,double degres,double minutes,double secondes){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Libeasy < Formula | |
homepage "http://gitlab.alibaba-inc.com/zicheng.lhs/libeasy" | |
head "http://gitlab.alibaba-inc.com/zicheng.lhs/libeasy.git" | |
version "1.0.3" | |
depends_on "libtool" => :build | |
depends_on "automake" => :build | |
depends_on "autoconf" => :build | |
def install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sprockets-rails/test/test_railtie.rb | |
def test_benchmark_assets_tag | |
app.configure do | |
config.assets.paths << FIXTURES_PATH | |
config.assets.precompile += ["bar.js", "bar.css"] | |
end | |
app.initialize! | |
require 'benchmark/ips' |
OlderNewer