On Thursday 09 September 2010 19:40:47 Dr. Smith wrote: > The class code below runs terribly slow. Conversely, when converted into a > function (albeit returning only one value), it runs fast. Any insights > into this or suggestions to get a function to return multiple types at > once? > > ...library code... > > module testlib; > import std.stdio, std.string; > > class classtest { > > int i, j; > > double[][] hit() { > > double[][] hi = new double[][](1000, 40); > > for(i = 1; i < 1000; i++) { > for(j = 1; j < 40; j++) { > hi[i][j] = (i); > } > } > return hi; > } > > double[][] hot() { > > double[][] ho = new double[][](1000, 40); > > for(i = 1; i < 1000; i++) { > for(j = 1; j < 40; j++) { > ho[i][j] = (j); > } > } > return ho; > } > > string stest () { > string hello = "yo!"; > return hello; > } > } > > ... calling code ... > > import std.stdio, std.string; > import testlib; > > void main() { > > classtest obj = new classtest; > int i, j; > > for(i = 1; i < obj.hit.length; i++) { > for(j = 1; j < obj.hit[i].length; j++) { > writefln("%s\t%f\t%f", obj.stest, obj.hit[i][j], obj.hot[i][j]); > } > } > }
By the way, it looks like what you're trying to do could be shrunk down to import std.stdio; void main() { for(float i = 1; i < 1000; ++i) { for(float j = 1; j < 40; ++j) writefln("yo!\t%f\t%f", i, j); } } and that runs _way_ faster. I don't understand why you're doing anything with arrays in the first place given what you're printing. But maybe you're just trying to show a simplified test case. - Jonathan M Davis