我正在尝试编写一个我试图测量其效率的脚本.我有一些问题:-
abs -n10000 -c100 http://localhost/testapp This is ApacheBench, Version 2.3 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests Server Software: Apache/2.2.10 Server Hostname: localhost Server Port: 80 Document Path: /testapp Document Length: 525 …
我正在尝试使用Java解析带有正则表达式的链接.
但我认为它变得太慢了.例如,要从以下位置提取所有链接:
......花了34642毫秒(34秒!!!)
这是正则表达式:
private final String regexp = "<a.*?\\shref\\s*=\\s*([\\\"\\']*)(.*?)([\\\"\\'\\s].*?>|>)";
Run Code Online (Sandbox Code Playgroud)
模式的标志:
private static final int flags = Pattern.CASE_INSENSITIVE | Pattern.DOTALL |Pattern.MULTILINE | Pattern.UNICODE_CASE | Pattern.CANON_EQ;
Run Code Online (Sandbox Code Playgroud)
代码可能是这样的:
private void processURL(URL url){
URLConnection connection;
Pattern pattern = Pattern.compile(regexp, flags);
try {
connection = url.openConnection();
InputStream in = connection.getInputStream();
BufferedReader bf = new BufferedReader(new InputStreamReader(in));
String html = new String();
String line = bf.readLine();
while(line!=null){
html += line;
line = bf.readLine();
}
bf.close();
Matcher matcher = pattern.matcher(html);
while (matcher.find()) {
System.out.println(matcher.group(2));
} …Run Code Online (Sandbox Code Playgroud) 我见过很多博客,其中作者讨论了快速基准测试,例如Antonio Cangiano"凌晨3点在一起投掷的Ruby 1.9.0 v Python 2.5.1 ".
有没有一种简单的方法可以将脚本计时到毫秒级,就像我不知道的那样?他可能使用OS X的内置函数或单个库吗?Python有一个标准的lib吗?
如果你只是采取阻力最小的路径并在凌晨3点把它扔到一起,你会怎么做?
这是基准
require 'benchmark'
# create random array
arr = 40000.times.map { rand(100000).to_s }
r1 = ''
r2 = ''
r3 = ''
Benchmark.bm do |x|
x.report {
r1 = (arr.map { |s|
"[#{s}]"
}).join
}
x.report {
r2 = arr.inject('') { |memo, s|
memo + "[#{s}]"
}
}
x.report {
r3 = ''
arr.each { |s|
r3 << "[#{s}]"
}
}
end
# confirm result is same
puts r1 == r2
puts r2 == r3
Run Code Online (Sandbox Code Playgroud)
这是结果
user system total real …Run Code Online (Sandbox Code Playgroud) 我的目标是在Redis服务器上实现大约80%的CPU使用率,这可以使我们的后端服务器设计受益.
使用Redis本身的基准测试时,很容易达到大约100%的CPU使用率:
$ redis-benchmark -h 192.168.1.6 -n 1000000 -c 50
Run Code Online (Sandbox Code Playgroud)
在此基准测试中,我们分配了50个客户端,以便在我们的redis服务器上推送1,000,000个请求(192.168.1.6)
但是在使用其他一些客户端工具(例如redis-lua或webdis)时,CPU使用率最低不到60%.
我在webdis和reids -lua中浏览了一些代码.webdis依赖于hired, redis-lua在Lua中实现,它基于socket(lua-socket).这些油脂是否会影响检测结果?
我还在redis-benchmark中浏览了一些代码,这是基准测试的主要工作redis-benchmark,似乎redis-benchmark使用了Redis中的代码,而我的测试客户端(webdis和redis-lua)则没有.
目前我的客户有两个选择,使用redis-lua或者像webdis一样,但是这两个没有很好地利用Redis(不到60%),还有更多的选择吗?或者除了redis-benchmark本身之外如何在redis-server上做好用 ?
我正在使用JJH,一个OpenJDK微基准测试工具.构建过程创建microbenchmarks.jar我调用java -jar并传递jar名称和JMH参数.
我想我们应该选择运行基准-server,为什么?
换句话说,我应该运行我的基准:
java -server -jar microbenchmarks.jar ...(jmh args)
Run Code Online (Sandbox Code Playgroud) 问题1:为什么JMH比简单更好System.getNanotime()?
问题2:从结果(看看benchmarking results部分)我可以得出什么结果validateLongKeyBinary比64%更快validateLongKeyAscii?
示例(代码):
import net.spy.memcached.util.StringUtils;
import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
public class KeyBench {
private static final String LONG_KEY = "thisIsAFunkyKeyWith_underscores_AndAlso334" +
"3252545345NumberslthisIsAFunkyKeyWith_underscores_AndAlso3343252545345Numbe" +
"rslthisIsAFunkyKeyWith_underscores_AndAlso3343252545345NumberslthisIsAFunkyK" +
"eyWith_underscores_AndAlso3343252545345Numbersl";
@GenerateMicroBenchmark
public void validateLongKeyBinary() {
StringUtils.validateKey(LONG_KEY, true);
}
@GenerateMicroBenchmark
public void validateLongKeyAscii() {
StringUtils.validateKey(LONG_KEY, false);
}
}
Run Code Online (Sandbox Code Playgroud)
基准测试结果
# Running: benchmarks.KeyBench.validateLongKeyAscii
Result : 393,667 ±(95%) 13,985 ±(99%) 20,094 ops/ms
Statistics: (min, avg, max) = (357,445, 393,667, 413,004), stdev = 19,552
Confidence intervals: 95% …Run Code Online (Sandbox Code Playgroud) 我需要对将参数作为输入的REST API进行基准测试。我想知道是否有一种方法可以使用wrk。现在我看不到这样的选择:
user@Ubuntu-K56CA:~/wrk$ ./wrk
Usage: wrk <options> <url>
Options:
-c, --connections <N> Connections to keep open
-d, --duration <T> Duration of test
-t, --threads <N> Number of threads to use
-s, --script <S> Load Lua script file
-H, --header <H> Add header to request
--latency Print latency statistics
--timeout <T> Socket/request timeout
-v, --version Print version details
Run Code Online (Sandbox Code Playgroud)
当我查看此文件时:https : //github.com/wg/wrk/blob/master/src/wrk.lua
我看不到params在任何地方使用过。同样params在wrk回购中grepping并没有产生任何有用的信息。
我想念什么吗?
如果我想研究机器人技术的RL算法,应该如何使用Gazebo 和 OpenAI Gym进行测试,训练和基准测试?我应该从OpenAI Gym入手,然后将具有良好分数的算法带入Gazebo环境中以应对现实情况吗?
我有Rust项目,包括集成测试(在/testsdir中)和基准测试(在/benchesdir中).在测试和长凳中我需要一些实用功能,但它们与我的箱子本身无关,所以我不能把它们放在/utils目录中.
处理这种情况的惯用方法是什么?
benchmarking ×10
java ×3
jmh ×2
performance ×2
profiling ×2
ruby ×2
lua ×1
openai-gym ×1
php ×1
python ×1
redis ×1
regex ×1
rest ×1
robotics ×1
ros ×1
rust ×1
rust-cargo ×1
testing ×1
wrk ×1