The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

CElliott (12) [Avatar] Offline
#1
Thanks to the authors for such a helpful book on Java 8, lambdas, and functional programming. I am almost finished reading it and have enjoyed all my time with it. I particularly liked Ch 12; I had spent many weeks studying the new time and date classes API documentation and thought I knew it all, but Ch 12 made several points I had completely missed. Thanks again.

I wrote a driver for the SubsetsMain example to see how large a set I could compute the number of subsets of and if immutable objects and the garbage collection they engender would scale up to larger problems. With 32GB of memory in the computer I was only able to compute the subsets of a set of size 25 before there was a problem. FWIIW, I used the bad example of concat, put an l.clear() line after the copyList.addAll(l); line in insertAll, and cleared subs in the driver with the lines for(List<Integer> l : subs) l.clear(); subs.clear(); to make SubsetsMain find all the subsets of a set of size 28. The final result was about 3 times faster than the initial attempt: about 5.92 secs vs. 15.22 secs to find the subsets of a set of size 25. The results were (Core i7 3820):

{
{# Subsets, Input Size, Time/Subset (s), TotalTime (s)},
{2, 1, 0.000847778, 0.00169556},
{4, 2, 6.826*10-6, 0.000027307},
{8, 3, 3.128*10-6, 0.000025031},
{16, 4, 3.537*10-6, 0.000056604},
{32, 5, 1.591*10-6, 0.000050915},
{64, 6, 1.084*10-6, 0.000069403},
{128, 7, 8.26*10-7, 0.000105813},
{256, 8, 6.25*10-7, 0.00016014},
{512, 9, 4.72*10-7, 0.00024206},
{1024, 10, 4.47*10-7, 0.000457951},
{2048, 11, 4.09*10-7, 0.000839388},
{4096, 12, 4.01*10-7, 0.00164265},
{8192, 13, 3.14*10-7, 0.00257903},
{16384, 14, 1.92*10-7, 0.00315361},
{32768, 15, 1.29*10-7, 0.004247},
{65536, 16, 1.23*10-7, 0.00810858},
{131072, 17, 9.4*10-8, 0.0124025},
{262144, 18, 7.*10-8, 0.0183653},
{524288, 19, 6.9*10-8, 0.0364506},
{1048576, 20, 6.2*10-8, 0.0655527},
{2097152, 21, 1.32*10-7, 0.277843},
{4194304, 22, 1.2*10-7, 0.506426},
{8388608, 23, 1.26*10-7, 1.06054},
{16777216, 24, 1.47*10-7, 2.47489},
{33554432, 25, 1.76*10-7, 5.93673},
{67108864, 26, 3.95*10-7, 26.5249},
{134217728, 27, 1.56*10-7, 20.9477},
{268435456, 28, 4.21*10-7, 113.09}}

Just to be a slightly annoying former colonial, myNextWorkingDay TemporalAdjuster in the DateTimeExamples (Ch 12) was almost twice as fast as yours. Here is the code:

private static class myNextWorkingDay implements TemporalAdjuster{
@Override
public Temporal adjustInto(Temporal temporal){
do{
temporal = temporal.plus(1, ChronoUnit.DAYS);
}while( DayOfWeek.of(temporal.get(ChronoField.DAY_OF_WEEK)) == DayOfWeek.SATURDAY ||
DayOfWeek.of(temporal.get(ChronoField.DAY_OF_WEEK)) == DayOfWeek.SUNDAY);
return temporal;
}
}

I once read a Java consultant's blog in which he wrote something like, If you want performance in Java, never save anything to memory. That was good advice, and I have treasured it ever since I saw it. It does impact readability, though.

Again, thanks for your very useful book and for all your hard work in researching and writing it.

Charles Elliott