100MHz 嵌入式处理器基准测试程序:DMIPS 和 FLOPS 计算
100MHz 嵌入式处理器基准测试程序:DMIPS 和 FLOPS 计算
要编写一个主频为 100MHz 的嵌入式处理器的基准测试程序,可以使用 Dhrystone MIPS(DMIPS)和浮点运算次数(FLOPS)来评估性能。
以下是一个参考的基准测试程序示例:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// Dhrystone基准测试程序
void dhrystone() {
struct {
int Int_Glob;
char Char_Glob_1;
char Char_Glob_2;
char Array_1_Dim_1[50];
char Array_1_Dim_2[50][50];
int Array_2_Dim_1[50];
int Array_2_Dim_2[50][50];
struct {
int Int_Comp;
char Char_Comp_1;
char Char_Comp_2;
} Rec_Type;
struct {
int Int_Comp;
char Char_Comp_1;
char Char_Comp_2;
} *Ptr_Comp;
int Enum_Comp;
int Int_Comp;
char String_Comp_1[31];
char String_Comp_2[31];
} Rec_Type_A, Rec_Type_B;
int Int_Loc_1;
int Int_Loc_2;
int Int_Loc_3;
char Char_Index;
char Char_Loc_1;
char Char_Loc_2;
int Enum_Loc;
char String_Loc_1[31];
char String_Loc_2[31];
int Run_Index;
int Number_Of_Runs;
Number_Of_Runs = 50000;
for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index) {
Proc_5();
Proc_4();
Int_Loc_1 = 2;
Int_Loc_2 = 3;
strcpy(String_Loc_1, 'DHRYSTONE PROGRAM, SOME STRING');
Enum_Loc = 1;
Rec_Type_A.Ptr_Comp = &Rec_Type_B;
Rec_Type_A.Int_Comp = 5;
Rec_Type_A.Enum_Comp = Enum_Loc;
Rec_Type_A.String_Comp_1 = String_Loc_1;
Rec_Type_A.String_Comp_2 = String_Loc_2;
Rec_Type_A.Int_Comp = Int_Loc_1 + 10;
do {
if (Rec_Type_A.String_Comp_1[Int_Loc_1] != 'A') {
Proc_6(Enum_Loc, &Rec_Type_A);
Int_Loc_3 = Int_Loc_2 * 2 - Int_Loc_1;
Rec_Type_A.Int_Comp = Int_Loc_3;
strcpy(Rec_Type_A.String_Comp_2, 'DHRYSTONE PROGRAM, 2'ND STRING');
Int_Loc_3 = Int_Loc_3 * Rec_Type_A.Int_Comp;
Int_Loc_2 = Int_Loc_3 / Rec_Type_A.Int_Comp;
Int_Loc_2 = 7 * (Int_Loc_3 - Int_Loc_2) - Int_Loc_1;
Proc_6(Enum_Loc, &Rec_Type_A);
Int_Loc_2 = Int_Loc_2 * Int_Loc_3;
Int_Loc_1 = Int_Loc_2 / Int_Loc_3;
Int_Loc_2 = 7 * (Int_Loc_2 - Int_Loc_1) - Int_Loc_3;
Proc_5();
}
} while (--Int_Loc_1 > 0);
Proc_4();
}
}
// 伪过程1
void Proc_1() {
Next_Ptr_Glob = Ptr_Glob;
Proc_3();
Int_Loc_1 = 2;
Int_Loc_2 = 3 * Int_Loc_1;
Int_Loc_1 = Int_Loc_2 / 7;
Int_Loc_2 = 1000 * (Int_Loc_2 - Int_Loc_1) * 7;
Proc_2(&Int_Loc_1);
}
// 伪过程2
void Proc_2(Int_Par_Ref) {
int Int_Loc;
int Enum_Loc;
Int_Glob = Int_Par_Ref + 10;
do {
if (Char_Glob_1 == 'A') {
Int_Loc = Int_Glob - Int_Par_Ref;
Enum_Loc = Ident_1;
}
} while (Enum_Loc != Ident_1);
}
// 伪过程3
void Proc_3() {
strcpy(Next_Ptr_Glob->String_Comp_1, 'DHRYSTONE PROGRAM, 3'RD STRING');
Next_Ptr_Glob->Int_Comp = 5;
Next_Ptr_Glob->Enum_Comp = Ident_1;
Next_Ptr_Glob->String_Comp_2 = malloc(30 * sizeof(char));
strcpy(Next_Ptr_Glob->String_Comp_2, 'DHRYSTONE PROGRAM, 3'RD STRING');
Ptr_Glob = Ptr_Glob->Ptr_Comp;
}
// 伪过程4
void Proc_4() {
int Bool_Loc;
Bool_Loc = Char_Glob_1 == 'A';
Bool_Glob = Bool_Loc | Bool_Glob;
Char_Glob_2 = 'B';
}
// 伪过程5
void Proc_5() {
Char_Glob_1 = 'A';
Bool_Glob = false;
}
// 伪过程6
void Proc_6(Enum_Val_Par, Enum_Ref_Par) {
Enum_Ref_Par = Enum_Val_Par;
if (!Func_3(Enum_Val_Par)) {
Enum_Ref_Par = Ident_4;
}
switch (Enum_Val_Par) {
case Ident_1:
Enum_Ref_Par = Ident_1;
break;
case Ident_2:
if (Int_Glob > 100) {
Enum_Ref_Par = Ident_1;
} else {
Enum_Ref_Par = Ident_4;
}
break;
case Ident_3:
Enum_Ref_Par = Ident_2;
break;
case Ident_4:
break;
case Ident_5:
Enum_Ref_Par = Ident_3;
break;
}
}
// 伪函数3
bool Func_3(Enum_Par_Val) {
Enum_Par_Val = Enum_Par_Val;
return true;
}
// 主函数
int main() {
clock_t start, end;
double cpu_time_used;
start = clock();
// 运行Dhrystone基准测试程序
dhrystone();
end = clock();
cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
// 计算DMIPS
double dmips = (double) Number_Of_Runs / (cpu_time_used / 1000000.0);
// 计算FLOPS
double flops = (double) Number_Of_Runs * 500 / (cpu_time_used * 1000000.0);
printf('DMIPS: %f\n', dmips);
printf('FLOPS: %f\n', flops);
return 0;
}
这个程序是一个 Dhrystone 基准测试程序的 C 语言实现,它模拟了一系列典型的程序操作。在主函数中,我们使用 clock 函数来计算程序的执行时间,并根据公式计算出 DMIPS 和 FLOPS 的值。最后,将这些值打印出来。
请注意,这个程序只是一个参考示例,你可能需要根据你的处理器架构和指令集进行适当的修改和优化。
原文地址: https://www.cveoy.top/t/topic/nE2w 著作权归作者所有。请勿转载和采集!