#!/usr/bin/perl -w

if ($ARGV[0] eq "WO") {
open("WO0", ">worker-sp") || die "open failed: $!";
open("WO2", ">worker-mp") || die "open fialed: $!";

for ($size = 0; $size < 327680; $size+=8192) {
	system("cc -DWORKER_POLLUTION_SIZE=$size ctx.c -o ctx.tmp -lpthread 2> /dev/null");

	@foo = `./ctx.tmp 5 1024 0 866`;
	@bar = splice(@foo,-11);

	$l = 0;
	for (@bar) {
		if (/^%.*?([0-9.]+)/) {
			if ($l < $1) {
				$l = $1;
			}
		}
	}

	print WO0 "$size\t$l\n";

	@foo = `./ctx.tmp 5 1024 2 866`;
	@bar = splice(@foo,-11);

	$l = 0;
	for (@bar) {
		if (/^%.*?([0-9.]+)/) {
			if ($l < $1) {
				$l = $1;
			}
		}
	}

	print WO2 "$size\t$l\n";
}

close(WO0);
close(WO2);
}

if ($ARGV[0] eq "ST") {
open("ST0", ">stack-sp") || die "open failed: $!";
open("ST2", ">stack-mp") || die "open fialed: $!";

for ($size = 0; $size < 40960; $size+=128) {
	system("cc -DSTACK_POLLUTION_SIZE=$size ctx.c -o ctx.tmp -lpthread 2> /dev/null");

	@foo = `./ctx.tmp 5 1024 0 866`;
	@bar = splice(@foo,-11);

	$l = 0;
	for (@bar) {
		if (/^%.*?([0-9.]+)/) {
			if ($l < $1) {
				$l = $1;
			}
		}
	}

	print ST0 "$size\t$l\n";

	@foo = `./ctx.tmp 5 1024 2 866`;
	@bar = splice(@foo,-11);

	$l = 0;
	for (@bar) {
		if (/^%.*?([0-9.]+)/) {
			if ($l < $1) {
				$l = $1;
			}
		}
	}

	print ST2 "$size\t$l\n";
}

close(ST0);
close(ST2);
}

if ($ARGV[0] eq "SH") {
open("SH0", ">shared-sp") || die "open failed: $!";
open("SH2", ">shared-mp") || die "open fialed: $!";

for ($size = 0; $size < 204800; $size+=1024) {
	system("cc -DSHARED_POLLUTION_SIZE=$size ctx.c -o ctx.tmp -lpthread 2> /dev/null");

	@foo = `./ctx.tmp 5 1024 0 866`;
	@bar = splice(@foo,-11);

	$l = 0;
	for (@bar) {
		if (/^%.*?([0-9.]+)/) {
			if ($l < $1) {
				$l = $1;
			}
		}
	}

	print SH0 "$size\t$l\n";

	@foo = `./ctx.tmp 5 1024 2 866`;
	@bar = splice(@foo,-11);

	$l = 0;
	for (@bar) {
		if (/^%.*?([0-9.]+)/) {
			if ($l < $1) {
				$l = $1;
			}
		}
	}

	print SH2 "$size\t$l\n";
}

close(SH0);
close(SH2);
}

