标签: benchmarking

就地向量修改的理论与实际性能的混淆

为了满足高性能数学库的需求,我一直在对各种方法进行基准测试,以在 Rust vec 上进行就地操作(最好通过引用)。这些方法是:

  • 使用显式 for 循环
  • 使用迭代器,然后使用 a map(),收集到一个新的 vec,并覆盖现有的
  • 使用迭代器然后使用for_each()

这是基准测试代码:

use std::time::{Instant, Duration};

const N_ITEMS: usize = 100000;
const N_BENCH_TIMES: i32 = 100;

fn bench_simple() {
    let mut a: Vec<i32> = vec![5; N_ITEMS];
    for i in a.iter_mut() {
        *i += 1;
    }
}

fn bench_iterator() {
    let mut a: Vec<i32> = vec![5; N_ITEMS];
    let a: Vec<i32> = a.iter_mut().map(|x| *x + 1).collect();
}

fn bench_foreach() {
    let mut a: Vec<i32> = vec![5; N_ITEMS];
    a.iter_mut().for_each(|x| *x += …
Run Code Online (Sandbox Code Playgroud)

benchmarking vector rust

0
推荐指数
1
解决办法
92
查看次数

在PHP中从if语句或从数组中获取值更快?

也许这是一个愚蠢的问题,但更快的是什么?

<?php

function getCss1 ($id = 0) {
    if ($id == 1) {
        return 'red';
    } else if ($id == 2) {
        return 'yellow';
    } else if ($id == 3) {
        return 'green';
    } else if ($id == 4) {
        return 'blue';
    } else if ($id == 5) {
        return 'orange';
    } else {
        return 'grey';
    }
}

function getCss2 ($id = 0) {
    $css[] = 'grey';
    $css[] = 'red';
    $css[] = 'yellow';
    $css[] = 'green';
    $css[] = 'blue';
    $css[] …
Run Code Online (Sandbox Code Playgroud)

php optimization benchmarking

-1
推荐指数
1
解决办法
136
查看次数

为什么那些Javascript代码段执行相同的操作?

obj = [1,2,3,4,5];
function iter(){
    for (var key in obj){
        key=key+key;
    };
};
function test1() { 
    iter(obj); 
};
function test2(){
    (function iter(obj){
        for (var key in obj){
            key=key+key;
        };
    })(obj);    
};
Run Code Online (Sandbox Code Playgroud)

这里,test1和test2都执行相同的操作,即使test2每次被调用时都会创建一个新函数.为什么?

javascript performance benchmarking

-1
推荐指数
1
解决办法
78
查看次数

简单的基准测试

快速简单的问题,我找不到一个好的解决方案:

什么是一个简单的循环,可以让处理器"咀嚼"至少十秒钟?我尝试过这样的事情,但他们眨眼间就完成了:

int max = 300000;
for (int i = 0; i < max; i++)
{
    //do some random math here
}
Run Code Online (Sandbox Code Playgroud)

是否有某种计算或其他操作可以在那里占用更多时间并使用一点处理器功率?或者另一种方法来实现这个目标?

c# benchmarking for-loop console-application

-1
推荐指数
1
解决办法
672
查看次数

我可以修复我的 GPU 时钟频率以确保一致的分析结果吗?

我想对几个 CUDA 内核进行一些比较分析。但是,其中一个在一个程序中运行,该程序为 GPU 加载更多工作,而另一个仅在测试工具中运行。

对于某些 GPU,这些情况意味着时钟频率会发生变化(可能不止一种时钟频率,因为有多种)。这种影响在像 Tesla T4 这样的设备(没有主动冷却)中尤为严重。

是否可以防止时钟速率因负载(或热条件)而改变?

我已经研究过这个nvidia-smi实用程序,它有一个名为clocks-的子命令,但它所做的只是以下内容:

clocks -- Control and query clock information.

Usage: nvidia-smi clocks [options]
options include:
   [-i | --id]: Enumeration index, PCI bus ID or UUID. Provide comma
                 separated values for more than one device
   [ | --sync-boost-list]: List all synchronous boost groups
   [ | --sync-boost-add]: Add a synchronous boost group

   [ | --sync-boost-remove]: Remove a synchronous boost group. Provide the group id
                 returned from --sync-boost-list

Run Code Online (Sandbox Code Playgroud)

......看起来这不是我需要的。当然,非 …

benchmarking profiling cuda clock

-1
推荐指数
1
解决办法
3299
查看次数

从表格中选择*从表格中选择col1,col2,col3

可能重复:
选择*vs选择列

我刚刚与我的一位同事讨论了SQL Server在存储过程中指定查询命令的性能.

所以我想知道哪一个比另一个更受欢迎,并说明背后的具体原因.

假设,我们有一个名为Employees的表 (EmpName,EmpAddress)

我们想要从表中选择所有记录.所以我们可以用两种方式编写查询,

  1. 从员工中选择*

  2. 从Employees中选择EmpName,EmpAddress

所以我想知道上述查询中是否存在任何特定的差异或性能问题,或者它们是否与SQL Server引擎相同.

更新:

  1. 让我们说表模式不会再改变了.因此未来维护没有意义.
  2. 性能方面,让我们说,使用率非常高,即数据库服务器上每秒数百万次点击.我希望两种方法都有清晰准确的性能评级.
  3. 没有对整个表进行索引.

sql sql-server performance benchmarking select

-2
推荐指数
3
解决办法
1603
查看次数

哪个有更好的表现?一个std :: array或C数组?

我一直以为c数组会比C++中的std :: array快,但是我根据访问速度做了一些基准测试,看起来std :: array更快.这是为什么?

c++ arrays performance benchmarking

-2
推荐指数
1
解决办法
2202
查看次数

基准测试(for循环的执行时间):我们不应该随着for循环限制的增加而具有单调递增函数

我想对for循环进行基准测试.我决定将for循环中的变量增加100并相应地测量时间.

#include <cstdio>
#include <ctime>
#include <time.h>
#include <iostream>
#include <random>
#include <iomanip>      // std::setprecision
using namespace std;

double difference(timespec start, timespec end);

int main()
{
    timespec time1, time2;

    for(int limit = 0; x < 100000; limit+= 100)
    {
      clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
      int temp = 0;
      for (int i = 0; i< limit; i++)
        temp+=temp;

      clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2);
      std::cout << std::fixed;
      std::cout << std::setprecision(5);
      cout<<x <<" " << difference(time1,time2)<<endl;
    }

    return 0;
}

double difference(timespec start, timespec end)
{
    timespec temp;
    if …
Run Code Online (Sandbox Code Playgroud)

c++ time benchmarking

-2
推荐指数
1
解决办法
99
查看次数

使用CAT或AWK读取文件以获得更好的执行时间

我有两个相同的脚本.在一个我使用的猫和其他它都是AWK.

这是第一个:

#!/bin/bash


        lines=$(cat /etc/passwd | wc -l)

        for ((i=1 ; i <=$lines ; i++ ))
        do
        user=$(cat /etc/passwd | awk -F : -vi=$i 'NR==i {print $1}')
        uid=$(cat /etc/passwd | awk -F : -vi=$i 'NR==i {print $3}')
        gid=$(cat /etc/passwd | awk -F : -vi=$i 'NR==i {print $4}')
        shell=$(cat /etc/passwd | awk -F : -vi=$i 'NR==i {print $7}')
        echo -e "User is : $user \t Uid is : $uid \t Gid is : $gid \t Shell is : $shell"
        done
Run Code Online (Sandbox Code Playgroud)

这是第二个: …

bash time benchmarking awk cat

-2
推荐指数
1
解决办法
109
查看次数

与Goroutines的基准

这里对Golang来说很新,并且在使用goroutines进行基准测试时遇到了问题.

我的代码在这里:

    type store struct{}

    func (n *store) WriteSpan(span interface{}) error {
        return nil
    }

    func smallTest(times int, b *testing.B) {
        writer := store{}
        var wg sync.WaitGroup
        numGoroutines := times
        wg.Add(numGoroutines)
        b.ResetTimer()
        b.ReportAllocs()
        for n := 0; n < numGoroutines; n++ {
            go func() {
                writer.WriteSpan(nil)
                wg.Done()
            }()
        }
        wg.Wait()
    }
    func BenchmarkTest1(b *testing.B) {
        smallTest(1000000, b)
    }

    func BenchmarkTest2(b *testing.B) {
        smallTest(10000000, b)
    }

Run Code Online (Sandbox Code Playgroud)

它看起来两个场景的运行时和分配应该是相似的,但运行它们会给我以下结果,这些结果有很大的不同.不知道为什么会这样?那些额外的分配来自哪里?

BenchmarkTest1-12 1000000000 0.26 ns/op 0 B/op 0 allocs/op

BenchmarkTest2-12 1 2868129398 ns/op 31872 B/op …

benchmarking go goroutine

-2
推荐指数
1
解决办法
229
查看次数