a few things:
1. Nobody extends from Thread any more. They implement Runnable instead.
2. validateInput("") will throw an exception.
3. readHostAndPort doesn't need nested tries, so make them flatter, e.g. try {x} catch (Yy) {;} catch (Z z) {;}
4. readHostAndPort() probably should have a finally {if (in !=null) in.close();} block
5. the server-side code should also tidy itself up if an exception is thrown. You can test it using Mockito or something.
Contract stuff to Seraphina Amaranth.
"You give me the awful impression - I hate to have to say - of someone who hasn't read any of the arguments against your position. Ever."
1. Nah, I have to extend Thread quite a bit, implementing Runnable doesn't allow you to do the more advance threading stuff. Still, he'd be fine just implementing Runnable, aye.
You probably want to free up the OS resources like ports btw... close() those streams/sockets/etc. Do that in a finally block, so stuff gets called even when you get an exception. Or if you're under Java 7, use the using() clause.
apache.commons.ioutils give you a nice closeQuietly() that you can use.
I need a bit of help.
I have a python script that fetches data from a database and makes graphs. It's a fair amount of data for each graph and there's a couple of hundred graphs. Now my program makes some nice graphs, but the speed is somewhat lacking. As I mentioned it's written in Python and I'm using matplotlib for the plotting.
Do any of you have a few suggestions to how I could either speed it up, use something other than matplotlib or how to do it in other languages? Other languages would be primarily Java (or C but that would be too much work I'm sure).
Define speed and how you implented it ...
More to the point, what have you done to investigate where the bottleneck is?
I mean, if you're selecting a million rows from the database one row at a time without reusing the db connection, it doesn't matter how fast your computation is.
Conversely, if you're doing something stupidly O(n^2) then you should look at that first.
Contract stuff to Seraphina Amaranth.
"You give me the awful impression - I hate to have to say - of someone who hasn't read any of the arguments against your position. Ever."
Generally speaking, Python wouldn't be the bottleneck in this kind of situation. It's probably the database, or more specifically, the queries.
meh
As far as my timing experiment go about 3/5 of the time is used getting data and the other 2/5 is used in matplotlib routines. I'm not too worried about the time of getting the data as I'll be moving the script onto the same server as the database soon, so that should speed that part of it up nicely.
Any O(n^2) has been weeded out a while ago.
Right now I fire off separate threads to get the data for each graph and once all the data has been collected I make all the graphs in one thread as matplotlib isn't thread safe.
Dunno about the rest of your bottlenecks but I can comment on the graphics... I write high performance charting software. All the free/commercial charting libraries available are pretty slow, as they target the lowest common denominator hardware and do everything in software. I do the graphics myself with OpenGL/DirectX. Can happily chart millions of datapoints whilst being able to smoothly scroll and zoom etc. Even took it a step further and wrapped it up so it can be integrated into a c# wpf application easily. Also did some opengl prototypes for android etc.
This is clearly an awful lot of work, but if you are interested I would suggest giving it a go. It's a good way to learn how to program graphics. The basic trick is everything must be converted to triangles, so get out pen and paper and draw diagram: given 2 points (x1,y1), (x2,y2) -> it is possible to generated a strip of 3 triangles that form the "shaded section" under these points going down to the axis. Drawing the chart line itself is easy, but everyone expects fancy shaded section. If using older graphics software, you gotta generate this geometry with cpu and then push to graphics card. If using newer stuff then use Geometry shader to "emit" the triangles from the input data.
Drawing graph is pretty easy, drawing the ruling and text labels is actually where the difficulty lies![]()
Old screenshot: http://dl.dropbox.com/u/4436079/imag...nshot-ARES.png (axis fail) Note how it's antialiased and stuff. This is great for screenshots, but causes shimmering artifacts when it scrolls >.<
Last edited by balistic void; April 20 2012 at 08:36:03 AM.
ingame: AntonioBanderas
Detecting epic potential, expecting epic fail.Ah yes, the fork: The poor man's trident
New question:
In ASM with more syntax & macros aka C: How do you deal with a set of cars and a set of elephants w/o writing a 2nd set of functions to return elephants?
C++ has templates, Java something similar, other languages just don't care, but how do I do it in C?
The Chippewa believed that the weasel could kill the dreaded wendigo giant by rushing up its anus.
Is there a list of what values one can pass to Windows API's? Like how do I know that MessageBox from user32.dll requires 4 values?
Code:[DllImport("user32.dll", CharSet=CharSet.Auto)] static extern int MessageBox(int hWnd, string text, string caption, int options); MessageBox(0 , "Text", "Caption", 0);
Read the documentation: http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
MessageBox was just an example. But the link you gave me seem to be what I'm looking for. Thanks.
If using VS you can just press F1 with cursor on the function you want, should open msdn.
Surprising how many starting / junior developers don't know this. Between the official documentation, stack overflow, and google I am able to figure out 99% of the issues I run into. The remaining require some experimentation of library code lookup. A major difference between senior and mid-level programers boils down to google-fu.
Bookmarks