我不想发动圣战.我只是想知道是否有这样的基准?或者也许你可以从你的经历中谈谈这个话题?
以下哪个node.js HTTP代理实现更具性能?
第一个实现是:
var http = require('http');
http.createServer(function(request, response) {
var proxy = http.createClient(80, "google.com")
var proxy_request = proxy.request(request.method, request.url, request.headers);
proxy_request.addListener('response', function (proxy_response) {
proxy_response.addListener('data', function(chunk) {
response.write(chunk, 'binary');
});
proxy_response.addListener('end', function() {
response.end();
});
response.writeHead(proxy_response.statusCode, proxy_response.headers);
});
request.addListener('data', function(chunk) {
proxy_request.write(chunk, 'binary');
});
request.addListener('end', function() {
proxy_request.end();
});
}).listen(8080);
Run Code Online (Sandbox Code Playgroud)
第二个使用stream.pipe(),它就像:
var http = require('http');
http.createServer(function(request, response) {
var proxy = http.createClient(80, "google.com");
var proxy_request = proxy.request(request.method, request.url, request.headers);
proxy_request.on('response', function (proxy_response) {
proxy_response.pipe(response);
response.writeHead(proxy_response.statusCode, proxy_response.headers);
}); …Run Code Online (Sandbox Code Playgroud) 我正在做一些 PHP 内存基准测试,我想知道是否有一种方法可以优化垃圾收集器以减少内存消耗(因为它在其他语言中是可能的,例如 JAVA)。
我在 php.ini 中只发现了三个与 GC 相关的可自定义参数:session.gc_probability,session.gc_divisor和session.gc_maxlifetime. 这仅适用于会话,我没有对此进行基准测试。
到目前为止我知道的可能优化与代码相关,例如避免循环引用和通过调用强制垃圾收集循环gc_collect_cycles()(感谢这篇文章http://www.alexatnet.com/comment/86)。
有人知道 PHP 内存管理中的任何配置技巧或良好做法吗?
Iv写了一些C#代码似乎正在花费它的甜蜜时间,但完成工作.然后我将代码重写为稍微快一点的版本,虽然它不是很快(它是一个cms管理区域功能,因此对网站不重要)
无论如何,它让我思考是否有任何工具/技术允许a/b测试asp.net/C#中的函数
我基本上想要提供两个函数,并为每个函数获取执行时间等.
有没有人遇到过这方面的工具?
有一个谷歌,并在这里看,但找不到任何基准两个功能的基准
我想我正在寻找jsPerf,但在vs2010和C#中
有任何想法吗?
我目前正在制作一个PHP计时器,用于检查某种完成某件事的方法与完成相同的一项工作(基本上是基准测试)相比要花费多少时间。
现在,我还想使该工具能够分辨出该特定方法占用了多少内存。
因此,有关更多信息,我正在使用microtime来检查开始时间,对该代码执行200万次循环,然后使用一些数学方法进行另一个microtime来检查所花费的时间,所以我想在外面微型时间范围,还检查内存使用情况。
这是我当前的代码:
// Set the amount of loops to do, default is 2000
$loops = 2000;
$start_time = microtime(true); // Start the timer
for($i = 0; $i < $loops; $i++) {
// Code to test
}
$total_time = microtime(true) - $start_time; // Stop the timer, and figure out the total
ob_end_flush(); // Enable output again
echo $total_time; // Echo the timer's result
?>
Run Code Online (Sandbox Code Playgroud) 以下脚本逐行读取gzip文件并解码JSON对象
Pkg.add("GZip")
Pkg.add("JSON")
using GZip
using JSON
stream = GZip.gzopen(Base.ARGS[1])
_started = time()
i = 0
for line in eachline(stream)
_j = JSON.parse(line)
if i % 10000 == 0
println(time()-_started)
end
i += 1
try
key_id = _j["some_id"]
except
pass
end
end
Run Code Online (Sandbox Code Playgroud)
输出:
0.7071459293365479
20.09155511856079
37.8870849609375
Run Code Online (Sandbox Code Playgroud)
与Python比较:
import os
import sys
import gzip
import datetime
import ujson as json
_started = datetime.datetime.now()
fh = gzip.open(sys.argv[1])
for i, line in enumerate(fh):
if i % 10000 == 0:
print datetime.datetime.now() - _started …Run Code Online (Sandbox Code Playgroud) 我刚刚开始学习 Java 中的 Streams 和并行,我想知道为什么普通的 for 循环IntStream在向数组添加项时比并行花费的时间更少。
package parallel;
import java.util.stream.IntStream;
public class Parallel {
public static void main(String[] args) {
final int[] intArray = new int[100000];
long startTime = System.currentTimeMillis();
IntStream.range(0, 100000).parallel().forEach(i -> intArray[i]=i);
long endTime = System.currentTimeMillis();
System.out.println("Parallel time: " + (endTime-startTime));
final int[] intArray2 = new int[100000];
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
startTime = System.currentTimeMillis();
for(int i = 0; i < 100000; i++){
intArray2[i] = …Run Code Online (Sandbox Code Playgroud) 我读到基于范围的循环在某些编程语言上具有更好的性能。在 Swift 中是这样的吗?例如在游乐场:
func timeDebug(desc: String, function: ()->() )
{
let start : UInt64 = mach_absolute_time()
function()
let duration : UInt64 = mach_absolute_time() - start
var info : mach_timebase_info = mach_timebase_info(numer: 0, denom: 0)
mach_timebase_info(&info)
let total = (duration * UInt64(info.numer) / UInt64(info.denom)) / 1_000
println("\(desc): \(total) µs.")
}
func loopOne(){
for i in 0..<4000 {
println(i);
}
}
func loopTwo(){
for var i = 0; i < 4000; i++ {
println(i);
}
}
Run Code Online (Sandbox Code Playgroud)
基于范围的循环
timeDebug("Loop One time"){
loopOne(); // …Run Code Online (Sandbox Code Playgroud) 我有一个11个节点的集群,9个是奴隶,2个是主人,与我之前的问题相同.我正在该集群上执行TestDFSIO基准测试,该集群使用CDH 5.8.0.
我从TestDFSIO结果得到以下输出.这是吞吐量吗?或者我是否需要从中计算吞吐量,例如文件数量乘以TestDFSIO结果通过其他方式?
请告诉我如何获得整个群集的吞吐量.
----- TestDFSIO ----- : write
Date & time: Mon Aug 29 07:28:01 MDT 2016
Number of files: 10000
Total MBytes processed: 8000000.0
Throughput mb/sec: 50.75090177850001
Average IO rate mb/sec: 85.83160400390625
IO rate std deviation: 82.41435666074283
Test exec time sec: 3149.755
Run Code Online (Sandbox Code Playgroud) 英特尔 (链接)的以下论文描述了一种对代码进行准确基准测试的方法。基准测试的核心内容如下(参见第 31 页):
preempt_disable();
raw_local_irq_save(flags);
asm volatile (
"CPUID\n\t"
"RDTSC\n\t"
"mov %%edx, %0\n\t"
"mov %%eax, %1\n\t": "=r" (cycles_high), "=r" (cycles_low):: "%rax", "%rbx", "%rcx", "%rdx"
);
/*call the function to measure here*/
asm volatile(
"CPUID\n\t"
"RDTSC\n\t"
"mov %%edx, %0\n\t"
"mov %%eax, %1\n\t": "=r" (cycles_high1), "=r" (cycles_low1):: "%rax", "%rbx", "%rcx", "%rdx"
);
raw_local_irq_restore(flags);
preempt_enable();
Run Code Online (Sandbox Code Playgroud)
我想知道:
raw_local_irq_save和raw_local_irq_restore做什么?preempt_disable和preempt_enable做什么?