wisefree

wisefree

V2EX member #56037, joined on 2014-02-16 09:38:49 +08:00
Per wisefree's settings, the topics list is hidden
Deals info, including closed deals, is not hidden
wisefree's recent replies
Nov 9, 2024
Replied to a topic by wisefree C++ 请教一个 C++性能问题
@mightybruce 多谢啦,我调整了一下,发现自己对高性能运算,确实没有了解太多
Nov 9, 2024
Replied to a topic by wisefree C++ 请教一个 C++性能问题
@CedarChen 好的,多谢
Nov 9, 2024
Replied to a topic by wisefree C++ 请教一个 C++性能问题
@lzoje 多谢,是这样的,我调整了用例,new 之后全部赋值
Nov 9, 2024
Replied to a topic by wisefree C++ 请教一个 C++性能问题
@neocanable 同意,我重新写了一个例子,也应该是缓存导致速度差异
Nov 9, 2024
Replied to a topic by wisefree C++ 请教一个 C++性能问题
@jark006 是的,重新写了一个例子,发现应该是缓存起作用
Nov 9, 2024
Replied to a topic by wisefree C++ 请教一个 C++性能问题
@awenxjtu 重新写了一个例子,应该就可以用你的说法解释了,附言没有发送没有用 markdown 语法,格式有点混乱
Nov 9, 2024
Replied to a topic by wisefree C++ 请教一个 C++性能问题
``` c++

#include <iostream>
#include <chrono>


int I = 360;
int J = 280;
int K = 3;

int idealI = 512;

void func1(int* arr, float* transArr)
{
auto startTime = std::chrono::steady_clock::now();

for (int i = 0; i < I; i++) {
for (int j = 0; j < J; j++) {
for (int k = 0; k < K; k++) {

int realIdx = (i * (K * J) + j * K + k) * 2;
int imagIdx = realIdx + 1;

int transRealIdx = (k * (J * I) + j * I + i) * 2;
int transImagIdx = transRealIdx + 1;

transArr[transRealIdx] = arr[realIdx] * 0.1f;
transArr[transImagIdx] = arr[imagIdx] * 0.1f;
}
}
}

auto endTime = std::chrono::steady_clock::now();

std::chrono::duration<double> diffTime = endTime - startTime;

std::cout << diffTime.count() << std::endl;
}


void func2(int* arr, float* transArr)
{
auto startTime = std::chrono::steady_clock::now();

for (int i = 0; i < I; i++) {
for (int j = 0; j < J; j++) {
for (int k = 0; k < K; k++) {
int realIdx = (i * (K * J) + j * K + k) * 2;
int imagIdx = realIdx + 1;

int transRealIdx = (k * (J * idealI) + j * idealI + i) * 2;
int transImagIdx = transRealIdx + 1;

transArr[transRealIdx] = arr[realIdx] * 0.1f;
transArr[transImagIdx] = arr[imagIdx] * 0.1f;
}
}
}

auto endTime = std::chrono::steady_clock::now();

std::chrono::duration<double> diffTime = endTime - startTime;

std::cout << diffTime.count() << std::endl;
}

int main(void)
{

// i j k
int* arr = new int[I * J * K * 2];
for (int i = 0; i < I; i++) {
for (int j = 0; j < J; j++) {
for (int k = 0; k < K; k++) {
int realIdx = (i * (K * J) + j * K + k) * 2;
int imagIdx = realIdx + 1;

arr[realIdx] = k;
arr[imagIdx] = k;
}
}
}

// k j i
float* transArr = new float[idealI * J * K * 2];

for (int i = 0; i < idealI; i++) {
for (int j = 0; j < J; j++) {
for (int k = 0; k < K; k++) {
int realIdx = (i * (K * J) + j * K + k) * 2;
int imagIdx = realIdx + 1;

transArr[realIdx] = 0;
transArr[imagIdx] = 0;
}
}
}

func1(arr, transArr);
func2(arr, transArr);


delete[] arr;
delete[] transArr;

return 0;
}
```
Jun 17, 2024
Replied to a topic by wisefree C++ 请教大家一个 C++线程池的问题
@ysc3839 是的,我也想过 RVO 最有可能
Jun 17, 2024
Replied to a topic by wisefree C++ 请教大家一个 C++线程池的问题
@zhaoloving 嗯嗯,我也想这么干,只是这个例子能编译通过,我没想明白
Jun 17, 2024
Replied to a topic by wisefree C++ 请教大家一个 C++线程池的问题
@ysc3839 SubmitTask 函数返回了 Result 这个动作,是有 copyable 语义的,我也不太懂这个例子
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5829 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 32ms · UTC 02:42 · PVG 10:42 · LAX 19:42 · JFK 22:42
♥ Do have faith in what you're doing.