A tiny program to benchmark image transpose algorithms
Here is the code:
#include <stdio.h>
#include <xmmintrin.h>
#include <windows.h> typedef __m128 Vec; typedef unsigned long long value_t; __forceinline value_t now()
{
LARGE_INTEGER n;
QueryPerformanceCounter(&n);
return n.QuadPart;
} inline void img_transpose(
Vec *dst_img,
Vec *src_img,
const int src_w,
const int src_h)
{
#pragma omp parallel for
for (int j = ; j < src_w; ++j)
{
for (int i = ; i < src_h; ++i)
{
dst_img[j * src_h + i] = src_img[i * src_w + j];
}
}
} inline void img_transpose_block(
Vec *dst_img,
Vec *src_img,
const int src_w,
const int src_h)
{
#pragma omp parallel for
for (int j = ; j < src_w; j += )
{
for (int i = ; i < src_h; i += )
{
const int nsize = min(j + , src_w);
const int msize = min(i + , src_h); for (int n = j; n < nsize; ++n)
{
for (int m = i; m < msize; ++m)
{
dst_img[n * src_h + m] = src_img[m * src_w + n];
}
}
}
}
} int main(int argc, char *argv[])
{
//// performance benchmark //// const int w = ;
const int h = ;
Vec *a = new Vec [w * h];
Vec *b = new Vec [w * h];
value_t start_time, end_time; LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
double ms_per_tick = 1000.0 / (double)freq.QuadPart; start_time = now(); for (int t = ; t < ; ++t)
{
img_transpose(b, a, w, h);
img_transpose(a, b, h, w);
} end_time = now();
printf("img_transpose: %f ms\n", (double)(end_time - start_time) * ms_per_tick); start_time = now(); for (int t = ; t < ; ++t)
{
img_transpose_block(b, a, w, h);
img_transpose_block(a, b, h, w);
} end_time = now();
printf("img_transpose_block: %f ms\n", (double)(end_time - start_time) * ms_per_tick); delete [] a;
delete [] b; //// algorithm validation ////
const int width = ;
const int height = ;
Vec *src_img = new Vec [width * height];
Vec *dst_img = new Vec [height * width]; for (int j = ; j < height; ++j)
{
for (int i = ; i < width; ++i)
{
src_img[j * width + i].m128_i32[] = i;
src_img[j * width + i].m128_i32[] = j;
}
} img_transpose_block(dst_img, src_img, width, height); for (int j = ; j < width; ++j)
{
for (int i = ; i < height; ++i)
{
int pi = dst_img[j * height + i].m128_i32[];
int pj = dst_img[j * height + i].m128_i32[]; if (pi != j || pj != i)
{
printf("Algorithm is wrong!!!\n");
goto END_OF_PROGRAM;
}
}
} END_OF_PROGRAM:
printf("All done\n"); return ;
}
A tiny program to benchmark image transpose algorithms的更多相关文章
- hey is a tiny program that sends some load to a web application.
hey is a tiny program that sends some load to a web application. DOS attack DOS攻击生成 https://github.c ...
- 自己动手写一个编译器Tiny语言解析器实现
然后,上一篇文章简介Tiny词法分析,实现语言.本文将介绍Tiny的语法分析器的实现. 1 Tiny语言的语法 下图是Tiny在BNF中的文法. 文法的定义能够看出.INNY语言有以下特点: 1 程序 ...
- Reading List on Automated Program Repair
Some resources: https://www.monperrus.net/martin/automatic-software-repair 2017 [ ] DeepFix: Fixing ...
- [io benchmark]常用磁盘基准/压力测试工具
Unix Disk I/O Benchmarks fio - NEW! fio is an I/O tool meant to be used both for benchmark and stres ...
- UVA - 10895 Matrix Transpose
UVA - 10895 Matrix Transpose Time Limit:3000MS Memory Limit:Unknown 64bit IO Format:%lld & % ...
- Awesome Go
A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...
- Go 语言相关的优秀框架,库及软件列表
If you see a package or project here that is no longer maintained or is not a good fit, please submi ...
- Awesome Go (http://awesome-go.com/)
A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...
- Awesome Go精选的Go框架,库和软件的精选清单.A curated list of awesome Go frameworks, libraries and software
Awesome Go financial support to Awesome Go A curated list of awesome Go frameworks, libraries a ...
随机推荐
- javascript中Date使用
<script type="text/javascript"> //返回当前日期和时间 var newDate=new Date(); ...
- VS代码页到设计页传值
代码页 public string titleZRclass = ""; 根据条件设置其值 设计页 <%=titleZRclass %>
- winform弹出文件和目录选择框
目录选择: FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.Description = "请选择文件路径&quo ...
- hook进程
https://www.cnblogs.com/Leo_wl/p/3311279.html https://blog.csdn.net/u013761036/article/details/65465 ...
- part1:5Linux命令详解
1.Linux命令介绍 Linux命令是对Linux系统进行管理的命令.对于Linux系统来说,无论是中央处理器.内存.磁盘驱动器.键盘.鼠标还是用户等都是文件.Linux系统管理的命令是它正常运行的 ...
- DataStage 八、清除日志
DataStage序列文章 DataStage 一.安装 DataStage 二.InfoSphere Information Server进程的启动和停止 DataStage 三.配置ODBC Da ...
- 2018.10.09 NOIP模拟 世界杯(图论+set优化)
传送门 貌似是防akakak题? 不是很清楚. 事实上如果两个人没有严格的大小关系,我们给他们两个连一条边. 这样可以构成很多连通块. 而且对于连通块a,ba,ba,b,aia_iai和bjb_jb ...
- 22. Valuing Water 珍惜水资源
. Valuing Water 珍惜水资源 ① Humanity uses a little less than half the water available worldwide.Yet occu ...
- Linux IPC 之信号量
信号量(也叫信号灯)是一种用于提供不同进程间或一个给定进程的不同线程间同步手段的原语. 信号量是进程/线程同步的一种方式,有时候我们需要保护一段代码,使它每次只能被一个执行进程/线程运行,这种工作就需 ...
- python操作数据库-安装
首先是下载软件: 链接:http://pan.baidu.com/s/1nvp1imX 密码:6i0x 之后就是一系列设置. 安装教程:自行百度就行.需要注意的是设置my.ini时,需要加上这些东西( ...