-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
java implementation of sortedIntersectionCount that avoids unnecessar…
…y boxing (#36) For whatever reason this function always boxes the Ints when implemented in scala. When I moved it to java I found it doesn't box them which brings the Kosarak benchmark down from ~105sec to ~62sec on my laptop. Also a few other cosmetic changes.
- Loading branch information
1 parent
3c2d25c
commit fed9110
Showing
7 changed files
with
59 additions
and
36 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
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
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,45 @@ | ||
package com.klibisz.elastiknn; | ||
|
||
/** | ||
* Java implementations of some particularly performance-critical code paths. | ||
*/ | ||
public class Hotspots { | ||
|
||
private static void unsortedException(int lit, int big) { | ||
throw new IllegalArgumentException(String.format("Called on unsorted array: %d came after %d", lit, big)); | ||
} | ||
|
||
public static int sortedIntersectionCount(int [] xs, int [] ys) { | ||
int n = 0; | ||
int xi = 0; | ||
int yi = 0; | ||
int xmax = Integer.MIN_VALUE; | ||
int ymax = Integer.MIN_VALUE; | ||
while (xi < xs.length && yi < ys.length) { | ||
int x = xs[xi]; | ||
int y = ys[yi]; | ||
if (x < xmax) unsortedException(x, xmax); | ||
else xmax = x; | ||
if (y < ymax) unsortedException(y, ymax); | ||
else ymax = y; | ||
if (x < y) xi += 1; | ||
else if (x > y) yi += 1; | ||
else { | ||
n += 1; | ||
xi += 1; | ||
yi += 1; | ||
} | ||
} | ||
while(xi < xs.length) { | ||
if (xs[xi] < xmax) unsortedException(xs[xi], xmax); | ||
xi += 1; | ||
} | ||
while(yi < ys.length) { | ||
if (ys[yi] < ymax) unsortedException(ys[yi], ymax); | ||
yi += 1; | ||
} | ||
return n; | ||
} | ||
|
||
|
||
} |
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
dependencies { | ||
implementation project(':core') | ||
runtime 'org.scala-lang:scala-library:2.12.8' | ||
implementation 'org.scala-lang:scala-library:2.12.8' | ||
runtime "org.scala-lang:scala-library:${scalaVersion}" | ||
implementation "org.scala-lang:scala-library:${scalaVersion}" | ||
implementation 'org.apache.commons:commons-math3:3.6.1' | ||
implementation 'org.apache.spark:spark-mllib_2.12:2.4.4' | ||
} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
0.1.0-PRE5 | ||
0.1.0-PRE6 |