Created
September 20, 2015 07:08
-
-
Save masami256/ebb7c5317ea26ce81d33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def read_file(filename) | |
ret = [] | |
File.open(filename) do |f| | |
f.each_line do |line| | |
ret << line.split(',')[1].to_i | |
end | |
end | |
return ret | |
end | |
if __FILE__ == $0 | |
if ARGV.length == 0 | |
puts("usage: #{$0} file") | |
exit(-1) | |
end | |
data = read_file(ARGV[0]) | |
average = data.inject(0.0) { |r, i| r += i } / data.size | |
mid = data.size % 2 == 0 ? data[data.size / 2 - 1, 2].inject(:+) / 2.0 : data[data.size / 2] | |
puts("Average, Median") | |
puts("#{average},#{mid}") | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _GNU_SOURCE | |
#include <unistd.h> | |
#include <sys/syscall.h> | |
#include <sys/types.h> | |
#include <sys/wait.h> | |
#include <sys/ipc.h> | |
#include <sys/shm.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
static inline unsigned long rdtsc(void) | |
{ | |
unsigned long a, d; | |
__asm__ volatile("rdtsc" : "=a"(a), "=d"(d)); | |
return (d << 32) | a; | |
} | |
static int create_shered_memory(int num_test) | |
{ | |
int ret = 0; | |
size_t size = num_test * 16; // keep 16 bytes for one line | |
ret = shmget(IPC_PRIVATE, size, 0666); | |
if (ret < 0) { | |
perror("semget"); | |
exit(-1); | |
} | |
return ret; | |
} | |
static inline void *do_shmat(int shmid) | |
{ | |
void *addr = shmat(shmid, NULL, 0); | |
if (addr < 0) { | |
perror("shmat"); | |
exit(-1); | |
} | |
return addr; | |
} | |
static inline void do_shmdt(void *addr) | |
{ | |
if (shmdt(addr) < 0) { | |
perror("shmdt"); | |
exit(-1); | |
} | |
} | |
int main(int argc, char **argv) | |
{ | |
unsigned long i, max = 1000; | |
unsigned long after, before; | |
char buf[64] = {0}; | |
int shmid; | |
char *shmaddr; | |
if (argc > 1) | |
max = strtoul(argv[1], NULL, 10); | |
shmid = create_shered_memory(max); | |
for (i = 0; i < max; i++) { | |
pid_t pid = fork(); | |
if (!pid) { // child | |
before = rdtsc(); | |
syscall(SYS_getpid); | |
after = rdtsc(); | |
sprintf(buf, "%lu,%lu\n", i, after - before); | |
shmaddr = do_shmat(shmid); | |
strcat(shmaddr, buf); | |
do_shmdt(shmaddr); | |
_exit(0); | |
} else if (pid > 0) { // parent | |
waitpid(pid, NULL, 0); | |
} else { | |
perror("fork()"); | |
exit(-1); | |
} | |
} | |
shmaddr = do_shmat(shmid); | |
printf("%s\n", shmaddr); | |
do_shmdt(shmaddr); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -ne 1 ]; then | |
echo "usage: ${0} name" | |
exit 1 | |
fi | |
name=$1 | |
for ((i = 0; i < 5; i++)); | |
do | |
./calc.rb ${name}_${i}.txt | |
done | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -ne 1 ]; then | |
echo "usage: ${0} name" | |
exit 1 | |
fi | |
name=$1 | |
for ((i = 0; i < 5; i++)); | |
do | |
echo "run test ${i}" | |
./pidns_tester 100000 > ${name}_${i}.txt | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment