您尚未登录。

楼主 #1 2021-01-27 22:37:44

uuid
会员
注册时间: 2020-12-08
已发帖子: 45
积分: 31

写了一个简单的Linux memcpy 测试函数, 大家可以看看各种平台的memcpy拷贝速度

memtest.c

#include <string.h>
#include <sys/time.h>
#include <stdlib.h>
#include <time.h>
#include <stdint.h>
#include <stdio.h>

#define ONE_MILLION   1000000
#define MEM_TEST_SIZE (100 * ONE_MILLION)

int main(int argc, char* argv[])
{
        if (argc < 2)
        {
                printf("usage: %s n (test n mega bytes)\n", argv[0]);
                exit(-1);
        }

        int n = abs(atoi(argv[1]));

        printf("now test copy %dM bytes.\n", n);

        uint8_t *src = (uint8_t *)malloc(n * ONE_MILLION);
        uint8_t *dst = (uint8_t *)malloc(n * ONE_MILLION);

        if(!src || !dst)
        {
                printf("alloc memory error!\n");
                exit(-2);
        }

        struct  timeval time_start;
        struct  timeval time_end;

        gettimeofday(&time_start,NULL);
        memcpy(dst, src, (n * ONE_MILLION));
        gettimeofday(&time_end,NULL);
        printf("calculate time: %ld us \n",
                (ONE_MILLION * time_end.tv_sec + time_end.tv_usec)-(ONE_MILLION*time_start.tv_sec + time_start.tv_usec)
              );

        free(dst);
        free(src);
        return 0;
 }

VMWARE + Ubuntu 18.04 测试:

$
$ ./memtest 1
now test copy 1M bytes.
calculate time: 665 us
$
$ ./memtest 10
now test copy 10M bytes.
calculate time: 6692 us
$
$ ./memtest 100
now test copy 100M bytes.
calculate time: 67354 us

离线

楼主 #2 2021-01-27 22:45:33

uuid
会员
注册时间: 2020-12-08
已发帖子: 45
积分: 31

Re: 写了一个简单的Linux memcpy 测试函数, 大家可以看看各种平台的memcpy拷贝速度

V3s DDR2
CPU 1GHz, DDR CLK 360MHz

# memtest 1
now test copy 1M bytes.
calculate time: 4300 us
#
#
#
# memtest 10
now test copy 10M bytes.
calculate time: 50673 us
#
#
#
# memtest 15
now test copy 15M bytes.
calculate time: 82828 us

离线

楼主 #3 2021-01-27 22:49:57

uuid
会员
注册时间: 2020-12-08
已发帖子: 45
积分: 31

Re: 写了一个简单的Linux memcpy 测试函数, 大家可以看看各种平台的memcpy拷贝速度

V3s DDR3 (相当于S3)
CPU 1GHz, DDR CLK 360MHz

# memtest 1
now test copy 1M bytes.
calculate time: 2458 us
#
# memtest 10
now test copy 10M bytes.
calculate time: 24788 us
#
#
# memtest 15
now test copy 15M bytes.
calculate time: 37431 us
#
# memtest 3
now test copy 3M bytes.
calculate time: 7528 us
#
#
# memtest 3
now test copy 3M bytes.
calculate time: 7294 us
#
#
# memtest 3
now test copy 3M bytes.
calculate time: 7329 us

同频率下,DDR2比DDR3快了一倍多.

离线

#4 2021-01-27 23:53:25

微凉VeiLiang
会员
所在地: 深圳
注册时间: 2018-10-28
已发帖子: 595
积分: 525
个人网站

Re: 写了一个简单的Linux memcpy 测试函数, 大家可以看看各种平台的memcpy拷贝速度

还有这回事,ddr3为什么会慢过ddr2

离线

楼主 #5 2021-01-28 09:09:25

uuid
会员
注册时间: 2020-12-08
已发帖子: 45
积分: 31

Re: 写了一个简单的Linux memcpy 测试函数, 大家可以看看各种平台的memcpy拷贝速度

微凉VeiLiang 说:

还有这回事,ddr3为什么会慢过ddr2

不好意思, 前面写错了。应该是同频率下,DDR3比DDR2快了一倍多.

离线

楼主 #6 2021-01-28 19:12:49

uuid
会员
注册时间: 2020-12-08
已发帖子: 45
积分: 31

Re: 写了一个简单的Linux memcpy 测试函数, 大家可以看看各种平台的memcpy拷贝速度

#
# ./memtest 1
now test copy 1M bytes.
calculate time: 4373 us
#
#
# ./memtest 2
now test copy 2M bytes.
calculate time: 9216 us
#
# ./memtest 3
now test copy 3M bytes.
calculate time: 13578 us
#
# ./memtest 10
now test copy 10M bytes.
calculate time: 44411 us
#
# ./memtest 15
now test copy 15M bytes.
calculate time: 67031 us
#
# ./memtest 30
now test copy 30M bytes.
calculate time: 133734 us
#
# ./memtest 50
now test copy 50M bytes.
calculate time: 221139 us
#

奇怪, 为什么X3 比 V3s DDR3版本(S3) 更慢?

CONFIG_DRAM_CLK=552
CONFIG_DRAM_ZQ=15291
# CONFIG_DRAM_ODT_EN is not set
CONFIG_SYS_CLK_FREQ=1008000000

最近编辑记录 uuid (2021-01-28 19:15:59)

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn