-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb_ethernet_bench.c
More file actions
76 lines (62 loc) · 1.24 KB
/
b_ethernet_bench.c
File metadata and controls
76 lines (62 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "libBareMetal.h"
#define INTERFACE 0
u64 string_len(char* str)
{
int len = 0;
while (str[len] != '\0')
len++;
return len;
}
void reverse(char* str)
{
u64 len = string_len(str);
for (int i = 0; i < len / 2; i++)
{
char temp = str[i];
str[i] = str[len - i - 1];
str[len - i - 1] = temp;
}
}
void int_to_string(u64 num, char* str)
{
int i = 0;
do{
str[i++] = num % 10 + '0';
num /= 10;
} while (num);
str[i] = '\0';
reverse(str);
}
void print_u64(u64 num)
{
char str[21];
int_to_string(num, str);
b_output(str, string_len(str));
}
int main()
{
const int iterations = 1000000;
u64 start, end, total_ns, avg_ns, recv_packet_len = 0;
unsigned char *buffer;
b_output("Iterations: ", 12);
print_u64(iterations);
b_output("\n", 1);
// Record start time
start = b_system(TIMECOUNTER, 0, 0);
for (int i = 0; i < iterations; i++)
{
recv_packet_len += b_net_rx((void**)&buffer, INTERFACE);
}
// Record end time
end = b_system(TIMECOUNTER, 0, 0);
// Calculate the difference in nanoseconds
total_ns = end - start;
// Calculate average
avg_ns = total_ns / iterations;
// Display results
b_output("Average: ", 9);
print_u64(avg_ns);
b_output (" ns\nBytes received: ", 20);
print_u64(recv_packet_len);
return 0;
}