我想要一种能够对查询进行 1,000,000 次基准测试的方法。做到这一点最简单的方法是什么?目前,我已经多次搜索发出查询的方法,但没有弹出任何内容。
我还遇到过可以在 mysql 命令行中运行的 benchmark() 命令,但它似乎有一些限制,我似乎无法让它工作。
我已经看到 Go 中有一个结构testing.BenchmarkResult可以访问基准测试的结果,但我发现很少的文档或示例可以帮助我使用它。
到目前为止,我只对我的函数进行了这样的基准测试:
func BenchmarkMyFunction(b *testing.B) {
// call to myFunction
}
Run Code Online (Sandbox Code Playgroud)
然后运行:
go test -bench=".*"
Run Code Online (Sandbox Code Playgroud)
在这里,结果打印到控制台,但我想将它们存储在单独的文件中。我如何使用该BenchmarkResult类型来执行此操作?
这是针对 Python 3.6 的。
编辑并删除了很多无关紧要的内容。
我原以为json比 Stack Overflow 上的其他答案和评论更快pickle,看起来很多其他人也相信这一点。
我的测试合格吗?差距比我想象的要大得多。我在非常大的物体上测试得到了相同的结果。
import json
import pickle
import timeit
file_name = 'foo'
num_tests = 100000
obj = {1: 1}
command = 'pickle.dumps(obj)'
setup = 'from __main__ import pickle, obj'
result = timeit.timeit(command, setup=setup, number=num_tests)
print("pickle: %f seconds" % result)
command = 'json.dumps(obj)'
setup = 'from __main__ import json, obj'
result = timeit.timeit(command, setup=setup, number=num_tests)
print("json: %f seconds" % result)
Run Code Online (Sandbox Code Playgroud)
和输出:
pickle: 0.054130 seconds
json: 0.467168 seconds
Run Code Online (Sandbox Code Playgroud) 假设我们有一个数组a = np.array([1,2,0,4,0,5,0,0,11]),我们如何得到:
array([ 1, 2, 3, 4, 4.5, 5, 7, 9, 11])\nRun Code Online (Sandbox Code Playgroud)\n\n我尝试过的是:
\n\nfrom scipy.interpolate import interp1d\n\na = np.array([1,2,0,4,0,5,0,0,11])\nb = a[np.nonzero(a)]\nbrange = np.arange(b.shape[0])\ninterp = interp1d(brange, b)\nRun Code Online (Sandbox Code Playgroud)\n\n这似乎确实完成了寻找中间值的实际工作。例如:
\n\nprint (interp(1), interp(1.5), interp(2), interp(2.5), interp(3))\n#out: 2.0 3.0 4.0 4.5 5.0\nRun Code Online (Sandbox Code Playgroud)\n\n但我不知道如何从interp. 我也尝试了这个问题的解决方案,但该解决方案也遇到了完全相同的问题。
更新:
\n\n我使用 numpy 和 pandas 对这两个解决方案进行了快速基准测试,结果如下:
\n\ny = np.array([1,2,0,4,0,5,0,0,11])\n\ndef test1(y):\n\n x = np.arange(len(y))\n idx = np.nonzero(y)\n interp = interp1d(x[idx],y[idx])\n\n return interp(x)\n\ndef test2(y):\n s = pd.Series(y)\n …Run Code Online (Sandbox Code Playgroud) 我正在使用该库估计 GMM 模型plm。我有不同的时刻条件。
Z <- list(~YDWPP + ST_DEGREE, ~YDWPP + ST_DEGREE, ~YDWPP + ST_DEGREE,
~YDWPP + ST_DEGREE, ~YDWPP + ST_TRANSITIVITY, ~YDWPP + ST_STRUC_HOLE,
~YDWPP + ST_STRUC_HOLE, ~YDWPP + ST_STRUC_HOLE, ~YDWPP +
ST_STRUC_HOLE)
Z <- lapply(Z, as.formula)
lg.gmm <- list(c(4L, 8L), c(5L, 8L), c(6L, 8L), 7:8, 7:8, c(4L, 8L), c(5L,
8L), c(6L, 8L), 7:8)
Run Code Online (Sandbox Code Playgroud)
我正在为每组力矩限制运行一个循环Z,这样
out.1 <- list()
for(i in seq_along(Z)){
plm.gmm <-
pgmm(
dynformula(as.formula(model), lg),
data = pdata,
effect = 'twoway',
model = 'twostep',
transformation = …Run Code Online (Sandbox Code Playgroud) 如何使用-short中给出的标志go test -short?
是否可以组合-short和-benchmark标志?
我对 Go 语言还很陌生,但我正在努力让自己适应它的一些常见做法。其中一部分是尝试确保我的代码不仅以系统go test工作的方式添加了单元测试,而且go test -benchmark还以有用的方式运行。
目前我有一个基准测试,其中包括一系列基于不同大小的输入数据的子测试。运行 15 个排列需要很长时间,因此最好能提供缩短测试时间的选项。
我计划编写的下一组测试可能包括一系列数据输入示例。我希望运行其中的一个可以作为短期测试的健全性检查,但如果可以选择在较长(或正常)的测试运行中运行多个,那就太好了。
当我查看GoLang 文档中的测试标志时,它说“告诉长时间运行的测试以缩短其运行时间”。这听起来像是我想要的,但我无法弄清楚如何在测试代码中选取这个标志。
从效率方面来看,pandas“isin”和numpy“in1d”之间存在巨大差异。经过一些研究,我注意到数据的类型和作为参数传递给“in”方法的值对运行时间有巨大的影响。不管怎样,看起来 numpy 实现受到这个问题的影响要小得多。这里发生了什么?
import timeit
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randint(0,10,(10**6),dtype='int8'),columns=['A'])
vals = np.array([5,7],dtype='int64')
f = lambda: df['A'].isin(vals)
g = lambda: pd.np.in1d(df['A'],vals)
print 'pandas:', timeit.timeit(stmt='f()',setup='from __main__ import f',number=10)/10
print 'numpy :', timeit.timeit(stmt='g()',setup='from __main__ import g',number=10)/10
>>
**pandas: 0.0541711091995
numpy : 0.000645089149475**
Run Code Online (Sandbox Code Playgroud) 我正在使用 Google Benchmark 来测量某些代码的执行时间。例如,我编写了以下代码来测量其执行时间性能。
#include <benchmark/benchmark.h>
// Alternatively, can add libraries using linker options.
#ifdef _WIN32
#pragma comment ( lib, "Shlwapi.lib" )
#ifdef _DEBUG
#pragma comment ( lib, "benchmarkd.lib" )
#else
#pragma comment ( lib, "benchmark.lib" )
#endif
#endif
static void BenchmarkTestOne(benchmark::State& state) {
int Sum = 0;
while (state.KeepRunning())
{
for (size_t i = 0; i < 100000; i++)
{
Sum += i;
}
}
}
static void BenchmarkTestTwo(benchmark::State& state) {
int Sum = 0;
while (state.KeepRunning())
{
for …Run Code Online (Sandbox Code Playgroud) 我们正在为我们的堆栈评估 GraalVM。主要考虑因素之一是性能,这里有一些基准: https: //renaissance.dev/。
问题是我们希望看到其他语言实现的基准,而不是 OpenJDK 和 GraalVM 版本之间的基准。我唯一能找到的就是这篇文章,将它与 C2 进行比较。https://medium.com/graalvm/graalvm-20-1-7ce7e89f066b
我们的谷歌搜索没有发现任何其他结果。
我们在哪里可以找到更广泛的、跨语言的 GraalVM 基准测试?
我有两个源文件,它们的作用大致相同。唯一的区别是,在第一种情况下,函数作为参数传递,而在第二种情况下,函数作为参数传递。
\n第一种情况:
\nmodule Main where\n\nimport Data.Vector.Unboxed as UB\nimport qualified Data.Vector as V\n\nimport Criterion.Main\n\nregularVectorGenerator :: (Int -> t) -> V.Vector t\nregularVectorGenerator = V.generate 99999\n\nunboxedVectorGenerator :: Unbox t => (Int -> t) -> UB.Vector t\nunboxedVectorGenerator = UB.generate 99999\n\nmain :: IO ()\nmain = defaultMain\n [\n bench "boxed" $ whnf regularVectorGenerator (+2137)\n , bench "unboxed" $ whnf unboxedVectorGenerator (+2137)\n ]\nRun Code Online (Sandbox Code Playgroud)\n第二种情况:
\nmodule Main where\n\nimport Data.Vector.Unboxed as UB\nimport qualified Data.Vector as V\n\nimport Criterion.Main\n\nregularVectorGenerator :: Int -> V.Vector Int\nregularVectorGenerator = flip V.generate …Run Code Online (Sandbox Code Playgroud) benchmarking ×10
go ×2
numpy ×2
performance ×2
python ×2
c++ ×1
gmm ×1
graalvm ×1
haskell ×1
java ×1
json ×1
mysql ×1
pandas ×1
phpmyadmin ×1
pickle ×1
plm ×1
r ×1
scipy ×1
unit-testing ×1
windows ×1