-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e4f5df
commit 4e71330
Showing
11 changed files
with
624 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 @@ | ||
bin/ |
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,66 @@ | ||
public class Blender { | ||
|
||
private static class Color { | ||
double r, g, b; | ||
|
||
private Color(double r, double g, double b) { | ||
this.r = r; | ||
this.g = g; | ||
this.b = b; | ||
} | ||
|
||
public static Color color() { | ||
return new Color(0, 0, 0); | ||
} | ||
|
||
public void add(Color other) { | ||
r += other.r; | ||
g += other.g; | ||
b += other.b; | ||
} | ||
|
||
public void add(double nr, double ng, double nb) { | ||
r += nr; | ||
g += ng; | ||
b += nb; | ||
} | ||
|
||
public void multiply(double factor) { | ||
r *= factor; | ||
g *= factor; | ||
b *= factor; | ||
} | ||
} | ||
|
||
private static final Color[][][] colors = new Color[100][100][100]; | ||
|
||
public static void main(String[] args) { | ||
for (int j = 0; j < 10; j++) { | ||
long t = System.nanoTime(); | ||
for (int i = 0; i < 100; i++) { | ||
initialize(new Color(j / 20, 0, 1)); | ||
} | ||
long d = System.nanoTime() - t; | ||
System.out.println(d / 1_000_000 + " ms"); | ||
} | ||
} | ||
|
||
private static void initialize(Color id) { | ||
for (int x = 0; x < colors.length; x++) { | ||
Color[][] plane = colors[x]; | ||
for (int y = 0; y < plane.length; y++) { | ||
Color[] row = plane[y]; | ||
for (int z = 0; z < row.length; z++) { | ||
Color color = new Color(x, y, z); | ||
color.add(id); | ||
if ((color.r + color.g + color.b) % 42 == 0) { | ||
// PEA only allocates a color object here | ||
row[z] = color; | ||
} else { | ||
// Here the color object is not allocated at all | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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,60 @@ | ||
public class Blender2 { | ||
|
||
private static class Color { | ||
double r, g, b; | ||
|
||
private Color(double r, double g, double b) { | ||
this.r = r; | ||
this.g = g; | ||
this.b = b; | ||
} | ||
|
||
public static Color color() { | ||
return new Color(0, 0, 0); | ||
} | ||
|
||
public void add(Color other) { | ||
r += other.r; | ||
g += other.g; | ||
b += other.b; | ||
} | ||
|
||
public void add(double nr, double ng, double nb) { | ||
r += nr; | ||
g += ng; | ||
b += nb; | ||
} | ||
|
||
public void multiply(double factor) { | ||
r *= factor; | ||
g *= factor; | ||
b *= factor; | ||
} | ||
} | ||
|
||
private static final Color[][][] colors = new Color[100][100][100]; | ||
|
||
public static void main(String[] args) { | ||
for (int j = 0; j < 10; j++) { | ||
long t = System.nanoTime(); | ||
for (int i = 0; i < 100; i++) { | ||
initialize(new Color(j / 20, 0, 1)); | ||
} | ||
long d = System.nanoTime() - t; | ||
System.out.println(d / 1_000_000 + " ms"); | ||
} | ||
} | ||
|
||
private static void initialize(Color id) { | ||
for (int x = 0; x < colors.length; x++) { | ||
Color[][] plane = colors[x]; | ||
for (int y = 0; y < plane.length; y++) { | ||
Color[] row = plane[y]; | ||
for (int z = 0; z < row.length; z++) { | ||
Color color = new Color(x, y, z); | ||
color.add(id); | ||
} | ||
} | ||
} | ||
} | ||
} |
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,67 @@ | ||
public class Blender3 { | ||
|
||
private static boolean b; | ||
|
||
private static class Color { | ||
double r, g, b; | ||
|
||
private Color(double r, double g, double b) { | ||
this.r = r; | ||
this.g = g; | ||
this.b = b; | ||
} | ||
|
||
public static Color color() { | ||
return new Color(0, 0, 0); | ||
} | ||
|
||
public void add(Color other) { | ||
r += other.r; | ||
g += other.g; | ||
b += other.b; | ||
} | ||
|
||
public void add(double nr, double ng, double nb) { | ||
r += nr; | ||
g += ng; | ||
b += nb; | ||
} | ||
|
||
public void multiply(double factor) { | ||
r *= factor; | ||
g *= factor; | ||
b *= factor; | ||
} | ||
} | ||
|
||
private static final Color[][][] colors = new Color[100][100][100]; | ||
|
||
public static void main(String[] args) { | ||
b=args.length==1; | ||
for (int j = 0; j < 10; j++) { | ||
long t = System.nanoTime(); | ||
for (int i = 0; i < 100; i++) { | ||
initialize(new Color(j / 20, 0, 1)); | ||
} | ||
long d = System.nanoTime() - t; | ||
System.out.println(d / 1_000_000 + " ms"); | ||
} | ||
} | ||
|
||
private static void initialize(Color id) { | ||
for (int x = 0; x < colors.length; x++) { | ||
Color[][] plane = colors[x]; | ||
for (int y = 0; y < plane.length; y++) { | ||
Color[] row = plane[y]; | ||
for (int z = 0; z < row.length; z++) { | ||
Color color = new Color(x, y, z); | ||
color.add(id); | ||
if (!b && (color.r + color.g + color.b) % 42 == 0) { | ||
// PEA only allocates a color object here | ||
row[z] = color; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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,43 @@ | ||
public class Blender4 { | ||
|
||
private static class Color { | ||
double r; | ||
|
||
private Color(double r) { | ||
this.r = r; | ||
} | ||
|
||
public void add(Color other) { | ||
r += other.r; | ||
} | ||
} | ||
|
||
private static final Color[][][] colors = new Color[100][100][100]; | ||
|
||
public static void main(String[] args) { | ||
for (int j = 0; j < 10; j++) { | ||
long t = System.nanoTime(); | ||
for (int i = 0; i < 100; i++) { | ||
initialize(new Color(j / 20)); | ||
} | ||
long d = System.nanoTime() - t; | ||
System.out.println(d / 1_000_000 + " ms"); | ||
} | ||
} | ||
|
||
private static void initialize(Color id) { | ||
for (int x = 0; x < colors.length; x++) { | ||
Color[][] plane = colors[x]; | ||
for (int y = 0; y < plane.length; y++) { | ||
Color[] row = plane[y]; | ||
for (int z = 0; z < row.length; z++) { | ||
Color color = new Color(x); | ||
color.add(id); | ||
if (color.r % 42 == 0) { | ||
row[z] = color; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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,41 @@ | ||
public class Blender5 { | ||
|
||
private static class Color { | ||
double r; | ||
|
||
private Color(double r) { | ||
this.r = r; | ||
} | ||
|
||
public void add(Color other) { | ||
r += other.r; | ||
} | ||
} | ||
|
||
private static final Color[][][] colors = new Color[100][100][100]; | ||
|
||
public static void main(String[] args) { | ||
for (int j = 0; j < 10; j++) { | ||
long t = System.nanoTime(); | ||
for (int i = 0; i < 100; i++) { | ||
initialize(new Color(j / 20)); | ||
} | ||
long d = System.nanoTime() - t; | ||
System.out.println(d / 1_000_000 + " ms"); | ||
} | ||
} | ||
|
||
private static void initialize(Color id) { | ||
for (int x = 0; x < colors.length; x++) { | ||
Color[][] plane = colors[x]; | ||
for (int y = 0; y < plane.length; y++) { | ||
Color[] row = plane[y]; | ||
for (int z = 0; z < row.length; z++) { | ||
Color color = new Color(x); | ||
color.add(id); | ||
row[z] = color; | ||
} | ||
} | ||
} | ||
} | ||
} |
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,37 @@ | ||
public class Blender6 { | ||
|
||
private static class Color { | ||
double r; | ||
|
||
private Color(double r) { | ||
this.r = r; | ||
} | ||
|
||
public void add(Color other) { | ||
r += other.r; | ||
} | ||
} | ||
|
||
private static final Color[] colors = new Color[1000000]; | ||
|
||
public static void main(String[] args) { | ||
for (int j = 0; j < 10; j++) { | ||
long t = System.nanoTime(); | ||
for (int i = 0; i < 100; i++) { | ||
initialize(new Color(j / 20)); | ||
} | ||
long d = System.nanoTime() - t; | ||
System.out.println(d / 1_000_000 + " ms"); | ||
} | ||
} | ||
|
||
private static void initialize(Color id) { | ||
for (int x = 0; x < colors.length; x++) { | ||
Color color = new Color(x); | ||
color.add(id); | ||
if (color.r % 42 == 0) { | ||
colors[x] = color; | ||
} | ||
} | ||
} | ||
} |
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,40 @@ | ||
public class Blender7 { | ||
|
||
private static class Color { | ||
double r; | ||
|
||
private Color(double r) { | ||
this.r = r; | ||
} | ||
|
||
public void add(Color other) { | ||
r += other.r; | ||
} | ||
} | ||
|
||
private static final Color[][] colors = new Color[100][1000000]; | ||
|
||
public static void main(String[] args) { | ||
for (int j = 0; j < 10; j++) { | ||
long t = System.nanoTime(); | ||
for (int i = 0; i < 1; i++) { | ||
initialize(new Color(j / 20)); | ||
} | ||
long d = System.nanoTime() - t; | ||
System.out.println(d / 1_000_000 + " ms"); | ||
} | ||
} | ||
|
||
private static void initialize(Color id) { | ||
for (int x = 0; x < colors.length; x++) { | ||
Color[] row = colors[x]; | ||
for (int y = 0; y < row.length; y++) { | ||
Color color = new Color(x); | ||
color.add(id); | ||
if (color.r % 42 == 0) { | ||
row[y] = color; | ||
} | ||
} | ||
} | ||
} | ||
} |
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,21 @@ | ||
|
||
public class CountUppercase { | ||
static final int ITERATIONS = Math.max(Integer.getInteger("iterations", 1), 1); | ||
|
||
public static void main(String[] args) { | ||
String sentence = String.join(" ", args); | ||
for (int iter = 0; iter < ITERATIONS; iter++) { | ||
if (ITERATIONS != 1) | ||
System.out.println("-- iteration " + (iter + 1) + " --"); | ||
long total = 0, start = System.currentTimeMillis(), last = start; | ||
for (int i = 1; i < 10_000_000; i++) { | ||
total += sentence.chars().filter(Character::isUpperCase).count(); | ||
if (i % 1_000_000 == 0) { | ||
long now = System.currentTimeMillis(); | ||
last = now; | ||
} | ||
} | ||
System.out.printf("total: %d (%d ms)%n", total, System.currentTimeMillis() - start); | ||
} | ||
} | ||
} |
Oops, something went wrong.