Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragicafit committed Jan 21, 2022
1 parent 2e4f5df commit 4e71330
Show file tree
Hide file tree
Showing 11 changed files with 624 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin/
66 changes: 66 additions & 0 deletions Blender.java
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
}
}
}
}
}
}
60 changes: 60 additions & 0 deletions Blender2.java
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);
}
}
}
}
}
67 changes: 67 additions & 0 deletions Blender3.java
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;
}
}
}
}
}
}
43 changes: 43 additions & 0 deletions Blender4.java
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;
}
}
}
}
}
}
41 changes: 41 additions & 0 deletions Blender5.java
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;
}
}
}
}
}
37 changes: 37 additions & 0 deletions Blender6.java
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;
}
}
}
}
40 changes: 40 additions & 0 deletions Blender7.java
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;
}
}
}
}
}
21 changes: 21 additions & 0 deletions CountUppercase.java
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);
}
}
}
Loading

0 comments on commit 4e71330

Please sign in to comment.