Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance Improvements Part III #163

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/cpu_bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include <sys/utsname.h>

#include <stdlib.h>
#include <stdint.h>
#include <string.h>
Expand All @@ -30,33 +32,49 @@
#include "mem.h"
#include "utl.h"

#define CPU_BENCH_ITERATIONS (10 * 1000 * 1000)
uint64_t get_iterations() {
struct utsname name;
if (uname(&name) == 0) {
if (strcmp(name.machine, "x86_64") == 0) {
return 1000 * 1000 * 1000;
}
if (strcmp(name.machine, "armv6l") == 0) {
return 100 * 1000 * 1000;
}
}
return 10 * 1000 * 1000;
}

void test(struct cpu_t *cpu, uint8_t opcode) {
uint64_t runs[3];

struct cpu_instruction_t *ins = &cpu->instructions[opcode];

uint64_t iterations = get_iterations();

for (int run = 0; run < 3; run++) {
struct timespec start;
if (clock_gettime(CLOCK_REALTIME, &start) != 0) {
perror("Cannot get time");
exit(1);
}

cpu->state.x = 0x12;
cpu->state.y = 0x12;

switch (ins->bytes) {
case 1:
for (uint64_t i = 0; i < CPU_BENCH_ITERATIONS; i++) {
for (uint64_t i = 0; i < iterations; i++) {
((cpu_instruction_handler_t) ins->handler)(cpu);
}
break;
case 2:
for (uint64_t i = 0; i < CPU_BENCH_ITERATIONS; i++) {
for (uint64_t i = 0; i < iterations; i++) {
((cpu_instruction_handler_byte_t) ins->handler)(cpu, 0x12);
}
break;
case 3:
for (uint64_t i = 0; i < CPU_BENCH_ITERATIONS; i++) {
for (uint64_t i = 0; i < iterations; i++) {
((cpu_instruction_handler_word_t) ins->handler)(cpu, 0x1234);
}
break;
Expand Down
Loading