Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #8526

Re: slow as molasses

Date 2011-10-04 08:42 -0700
From Patricia Shanahan <pats@acm.org>
Newsgroups comp.lang.java.programmer
Subject Re: slow as molasses
References <e160619b-d172-4986-8e05-880d27473c5f@k15g2000yqd.googlegroups.com>
Message-ID <mJ-dnfccHKvwtBbTnZ2dnUVZ_tKdnZ2d@earthlink.com> (permalink)

Show all headers | View raw


On 10/4/2011 2:16 AM, bob wrote:
> So, I wrote some code, but it is slow as molasses.  Any easy ways to
> speed this up?
>
> 	float[] getVertices(String filename) {
>
> 		try {
> 			AssetManager am = this.getResources().getAssets();
> 			InputStream is = am.open(filename);
> 			Scanner s = new Scanner(is);
> 			long numfloats = s.nextLong();
> 			float[] f = new float[(int) numfloats];
> 			for (int ctr = 0; ctr<  f.length; ctr++) {
> 				f[ctr] = s.nextFloat();
> 			}
> 			return f;
>
> 		} catch (IOException e) {
> 			e.printStackTrace();
> 			return null;
> 		}
>
> 	}


As far as the performance issue is concerned, I agree with the comments
Andreas Leitgeb and Daniel Pitts have posted.

I'm just going to add a warning about the use of float. It is very easy
to get significant rounding errors in results that matter using float.
Almost always, double is a better choice.

I've seen situations in which float was the right choice, but they are rare.

Patricia

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

slow as molasses bob <bob@coolgroups.com> - 2011-10-04 02:16 -0700
  Re: slow as molasses Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-10-04 11:28 +0000
  Re: slow as molasses Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-10-04 07:47 -0700
  Re: slow as molasses Patricia Shanahan <pats@acm.org> - 2011-10-04 08:42 -0700
  Re: slow as molasses "John B. Matthews" <nospam@nospam.invalid> - 2011-10-04 13:30 -0400
    Re: slow as molasses bob <bob@coolgroups.com> - 2011-10-04 14:19 -0700

csiph-web