-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from skkuse/temporal_green_pattern
Merge green pattern
- Loading branch information
Showing
299 changed files
with
2,250 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.class | ||
__pycache__/ |
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
import time | ||
import subprocess | ||
import warnings | ||
|
||
warnings.filterwarnings("ignore", category=DeprecationWarning) | ||
|
||
from os import listdir | ||
from os.path import isfile, join | ||
|
||
jar_files = [f for f in listdir("./submission/") if isfile(join("./submission/", f))] | ||
|
||
for jar_name in jar_files: | ||
execution_result = subprocess.run(["java", "-jar", f"{jar_name}"], capture_output=True, cwd=f'./submission') | ||
try: | ||
execution_result.check_returncode() | ||
except subprocess.CalledProcessError as err: | ||
print(f"*******{jar_name} runtime error*******") | ||
raw_err = execution_result.stderr | ||
err = raw_err.decode("unicode_escape").strip() | ||
print(err) | ||
exit(0) | ||
|
||
print("===All files executed successfully===") | ||
print("======You are ready to submit!!======") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import subprocess | ||
|
||
from os import listdir | ||
from os.path import isfile, join | ||
|
||
patterns = [f for f in listdir("./patterns/") if not isfile(join("./patterns/", f))] | ||
|
||
for dir_name in patterns: | ||
bef_compilation_result = subprocess.run(["javac", "Before.java"], capture_output=True, cwd=f'./patterns/{dir_name}') | ||
aft_compilation_result = subprocess.run(["javac", "After.java" ], capture_output=True, cwd=f'./patterns/{dir_name}') | ||
try: | ||
bef_compilation_result.check_returncode() | ||
aft_compilation_result.check_returncode() | ||
except subprocess.CalledProcessError as err: | ||
bef_raw_err = bef_compilation_result.stderr | ||
aft_raw_err = aft_compilation_result.stderr | ||
err = bef_raw_err.decode("unicode_escape").strip() + "\n" + aft_raw_err.decode("unicode_escape").strip() | ||
print(err) | ||
exit(0) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import subprocess | ||
|
||
from os import listdir | ||
from os.path import isfile, join | ||
|
||
patterns = [f for f in listdir("./patterns/") if not isfile(join("./patterns/", f))] | ||
|
||
for dir_name in patterns: | ||
srcfiles = listdir(f"./patterns/{dir_name}") | ||
|
||
rmfiles = ["After.java", "Before.java", "After.class", "Before.class", "after.jar", "before.jar"] | ||
for file in rmfiles: | ||
if file in srcfiles: | ||
srcfiles.remove(file) | ||
|
||
bef_compression_result = subprocess.run(["jar", "cfe", "before.jar", "Before", "Before.class", *srcfiles], capture_output=True, cwd=f'./patterns/{dir_name}') | ||
aft_compression_result = subprocess.run(["jar", "cfe", "after.jar", "After", "After.class", *srcfiles], capture_output=True, cwd=f'./patterns/{dir_name}') | ||
try: | ||
bef_compression_result.check_returncode() | ||
aft_compression_result.check_returncode() | ||
except subprocess.CalledProcessError as err: | ||
bef_raw_err = bef_compression_result.stderr | ||
aft_raw_err = aft_compression_result.stderr | ||
err = bef_raw_err.decode("unicode_escape").strip() + "\n" + aft_raw_err.decode("unicode_escape").strip() | ||
print(err) | ||
exit(0) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
import time | ||
import subprocess | ||
import warnings | ||
|
||
warnings.filterwarnings("ignore", category=DeprecationWarning) | ||
|
||
from os import listdir | ||
from os.path import isfile, join | ||
|
||
patterns = [f for f in listdir("./patterns/") if not isfile(join("./patterns/", f))] | ||
|
||
for dir_name in patterns: | ||
# measure Before.java execution time | ||
|
||
bef_execution_time = 0 | ||
start_time = time.perf_counter() | ||
execution_result = subprocess.run(["java", "-jar", "before.jar"], capture_output=True, cwd=f'./patterns/{dir_name}') | ||
bef_execution_time += (time.perf_counter()-start_time) | ||
try: | ||
execution_result.check_returncode() | ||
except subprocess.CalledProcessError as err: | ||
raw_err = execution_result.stderr | ||
err = raw_err.decode("unicode_escape").strip() | ||
print(err) | ||
# some other error handlings | ||
exit(0) | ||
|
||
# measure After.java execution time | ||
aft_execution_time = 0 | ||
start_time = time.perf_counter() | ||
execution_result = subprocess.run(["java", "-jar", "after.jar"], capture_output=True, cwd=f'./patterns/{dir_name}') | ||
aft_execution_time += (time.perf_counter()-start_time) | ||
try: | ||
execution_result.check_returncode() | ||
except subprocess.CalledProcessError as err: | ||
raw_err = execution_result.stderr | ||
err = raw_err.decode("unicode_escape").strip() | ||
print(err) | ||
# some other error handlings | ||
exit(0) | ||
|
||
print(f"============= Result ({dir_name}) =============") | ||
print(f"[Before.jar] runtime: {bef_execution_time:0.4f}s") | ||
print(f"[After.jar ] runtime: {aft_execution_time:0.4f}s") | ||
if bef_execution_time > aft_execution_time: | ||
print(f"=> runtime decreased by {bef_execution_time-aft_execution_time:0.4f}s") | ||
else: | ||
print("=> runtime has not decreased...") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public class After { | ||
public static void main(String[] args){ | ||
// write after code | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public class Before { | ||
public static void main(String[] args){ | ||
// write before code | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import java.util.Arrays; | ||
import java.util.Random; | ||
|
||
public class After { | ||
|
||
public static void main(String[] args) { | ||
for (int k = 0 ; k < 1000 ; k++){ | ||
int[] data = new int[1000000]; | ||
Random random = new Random(); | ||
|
||
|
||
for (int i = 0; i < data.length; i++) { | ||
data[i] = random.nextInt(1000000); | ||
} | ||
Arrays.parallelSort(data); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import java.util.Arrays; | ||
import java.util.Random; | ||
|
||
public class Before { | ||
|
||
public static void main(String[] args) { | ||
for (int k = 0 ; k < 1000 ; k++){ | ||
int[] data = new int[1000000]; | ||
Random random = new Random(); | ||
|
||
for (int i = 0; i < data.length; i++) { | ||
data[i] = random.nextInt(1000000); | ||
} | ||
Arrays.sort(data); | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import java.util.Arrays; | ||
|
||
public class After { | ||
public static void main(String[] args) { | ||
int[] array = new int[10000000]; | ||
|
||
|
||
for (int num : array) { | ||
num = num * 2; | ||
} | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import java.util.Arrays; | ||
|
||
public class Before { | ||
public static void main(String[] args) { | ||
int[] array = new int[10000000]; | ||
|
||
|
||
for (int i = 0; i < array.length; i++) { | ||
array[i] = array[i] * 2; | ||
} | ||
|
||
} | ||
} |
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import java.util.stream.IntStream; | ||
|
||
|
||
public class After { | ||
public static void main(String[] args) { | ||
long sum = 0; | ||
|
||
for(int k = 0 ; k < 100 ; k++){ | ||
int[] arr = IntStream.range(1,100000000).toArray(); | ||
int len = arr.length; | ||
int i; | ||
|
||
for (i = 0; i < len - 10; i += 10) { | ||
sum += arr[i] + arr[i + 1] + arr[i + 2] + arr[i + 3] + arr[i+4] + arr[i + 5] + arr[i + 6] + arr[i + 7] + arr[i+8] + arr[i + 9]; | ||
} | ||
|
||
while (i < len) { | ||
sum += arr[i]; | ||
i++; | ||
} | ||
} | ||
System.out.println(sum); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import java.util.stream.IntStream; | ||
|
||
|
||
public class Before { | ||
public static void main(String[] args) { | ||
long sum = 0; | ||
|
||
for(int k = 0 ; k < 100 ; k++){ | ||
int[] arr = IntStream.range(1,100000000).toArray(); | ||
int len = arr.length; | ||
int i; | ||
|
||
for (i = 0 ; i < len ; i++) { | ||
sum += arr[i]; | ||
} | ||
} | ||
System.out.println(sum); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public class After { | ||
|
||
public static void main(String[] args) { | ||
for (int i = 0; i < 100000; i++) { | ||
|
||
String myString2 = "Object " + i; | ||
System.out.println(myString2); | ||
|
||
myString2 = null; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
public class Before { | ||
public static void main(String[] args) { | ||
for (int i = 0; i < 100000; i++) { | ||
|
||
String myString = new String("Object " + i); | ||
System.out.println(myString); | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
|
||
public class After { | ||
public static void main(String[] args) { | ||
|
||
for (int i = 0 ; i < 100000 ; i++){ | ||
Map<String, Integer> hashMap = new HashMap<>(); | ||
hashMap.put("Alice", 25); | ||
hashMap.put("Bob", 30); | ||
hashMap.put("Eve", 22); | ||
|
||
|
||
for (Map.Entry<String, Integer> entry : hashMap.entrySet()) { | ||
System.out.println(entry.getKey() + ": " + entry.getValue()); | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
public class Before { | ||
public static void main(String[] args) { | ||
|
||
for (int i = 0 ; i < 100000 ; i++){ | ||
Map<String, Integer> treeMap = new TreeMap<>(); | ||
treeMap.put("Alice", 25); | ||
treeMap.put("Bob", 30); | ||
treeMap.put("Eve", 22); | ||
|
||
for (Map.Entry<String, Integer> entry : treeMap.entrySet()) { | ||
System.out.println(entry.getKey() + ": " + entry.getValue()); | ||
} | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
28 changes: 28 additions & 0 deletions
28
green_pattern/patterns/Row-major_than_Column-major/After.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import java.util.Random; | ||
|
||
public class After { | ||
public static void main(String[] args) { | ||
long totalSum = 0; | ||
for (int p = 0 ; p < 1000 ; p++){ | ||
int rows = 1000; | ||
int cols = 1000; | ||
int[][] array = new int[rows][cols]; | ||
Random random = new Random(); | ||
|
||
|
||
for (int i = 0; i < rows; i++) { | ||
for (int k = 0; k < cols; k++) { | ||
array[i][k] = random.nextInt(100); | ||
} | ||
} | ||
|
||
for (int i = 0; i < array.length; i++) { | ||
int[] row = array[i]; | ||
for (int k = 0; k < row.length; k++) { | ||
totalSum += row[k]; | ||
} | ||
} | ||
} | ||
System.out.println(totalSum); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
green_pattern/patterns/Row-major_than_Column-major/Before.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import java.util.Random; | ||
|
||
public class Before { | ||
public static void main(String[] args) { | ||
long totalSum = 0; | ||
for (int p = 0 ; p < 1000 ; p++){ | ||
int rows = 1000; | ||
int cols = 1000; | ||
int[][] array = new int[rows][cols]; | ||
Random random = new Random(); | ||
|
||
|
||
for (int k = 0; k < cols; k++) { | ||
for (int i = 0; i < rows; i++) { | ||
array[i][k] = random.nextInt(100); | ||
} | ||
} | ||
|
||
for (int k = 0; k < cols; k++) { | ||
for (int i = 0 ; i < rows ; i++){ | ||
totalSum += array[i][k]; | ||
} | ||
|
||
} | ||
} | ||
System.out.println(totalSum); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Oops, something went wrong.