本文对NiosII 处理器的经济型Nios II/e和快速型Nios II/f在不同的优化方式下测试其性能,测试了以下代码的运行时间。

1、Printf//文件打印

2、usleep(1000)//睡眠时间

3、IOWR_ALTERA_AVALON_PIO_DATA//端口读写

测试代码如下:

#include <stdio.h>
#include "system.h"
#include "unistd.h"
#include "altera_avalon_performance_counter.h"
#include "altera_avalon_pio_regs.h"

int main()
{
    PERF_RESET(PERFORMANCE_COUNTER_BASE);
    PERF_START_MEASURING(PERFORMANCE_COUNTER_BASE);
    PERF_BEGIN(PERFORMANCE_COUNTER_BASE,1);
    printf("Hello from Nios II!\n");//test printf
    PERF_END(PERFORMANCE_COUNTER_BASE,1);
    PERF_BEGIN(PERFORMANCE_COUNTER_BASE,2);
    usleep(1000);//test usleep
    PERF_END(PERFORMANCE_COUNTER_BASE,2);
    PERF_BEGIN(PERFORMANCE_COUNTER_BASE,3);
    //IOWR_ALTERA_AVALON_PIO_DATA(PIO_BASE,0x00);//test IOWR
    IOWR(PIO_BASE,0,0x00);
    PERF_END(PERFORMANCE_COUNTER_BASE,3);
    PERF_STOP_MEASURING(PERFORMANCE_COUNTER_BASE);
    perf_print_formatted_report(PERFORMANCE_COUNTER_BASE,alt_get_cpu_freq(),
                                3,"printf","usleep","IOWR");
  return 0;
}

  测试结果如下:

表一:Nios II/e,没有优化

Section

%

Time (sec)

Time (clocks)

Occurrences

printf

20.9

0.00113

56317

1

usleep

79

0.00427

213400

1

IOWR

0.0459

0.00000

124

1

 

  表二:Nios II/e,优化:optimize -03

Section

%

Time (sec)

Time (clocks)

Occurrences

printf

13.9

0.00065

32648

1

usleep

86

0.00404

201865

1

IOWR

0.0383

0.00000

90

1

 

  表三:Nios II/e,优化:optimize -0s

Section

%

Time (sec)

Time (clocks)

Occurrences

printf

13.4

0.00063

31439

1

usleep

86.5

0.00405

202681

1

IOWR

0.0358

0.00000

84

1

 

  表四:Nios II/f,没有优化

Section

%

Time (sec)

Time (clocks)

Occurrences

printf

18.7

0.00023

11387

1

usleep

81.1

0.00099

49290

1

IOWR

0.0428

0.00000

26

1

 

  表五:Nios II/f,优化:optimize -03

Section

%

Time (sec)

Time (clocks)

Occurrences

printf

11

0.00012

5969

1

usleep

88.9

0.00097

48281

1

IOWR

0.0147

0.00000

8

1

 

  表六:Nios II/f,优化:optimize -0s

Section

%

Time (sec)

Time (clocks)

Occurrences

printf

12.1

0.00013

6653

1

usleep

87.8

0.00097

48315

1

IOWR

0.0473

0.00000

26

1

  通过比较上述六个表格数据,NiosII/e和NiosII/f性能还是相差比较大,从表格中数据看性能差4倍以上,同样的处理器优化之后性能比优化之前提升25%左右,而对于-03优化和-0S优化,性能基本差不多。而且usleep(1000),即延时1ms只有在NiosII/f中运行,才具有所设定的延时,在NiosII/e中实际延时时间为程序指定时间(1ms)的4倍左右,即4ms。

  根据Altera提供的资料:
 In Nios II Performance Benchmarks (Alteras document) are this DMIPS ratio: Nios II /f - 1.105, Nios II /s - 0.518, Nios II /e - 0.107


  即如果采用50MHz时钟,CUP的DMIPS为


  Nios II/f:1.105*50=55.25 DMIPS
  Nios II/s:0.518*50=25.9 DMIPS
  Nios II/e:0.107*50=5.35 DMIPS


  该性能的条件是在onchip-mem中运行,optimize为-03。cycloneII器件。本文中的程序在外接SDRAM中运行

 posted on 2011-12-11 20:44  _轩小宸  阅读(330)  评论(0编辑  收藏  举报