Post: The way you write out your program matters
05-10-2013, 05:47 AM #1
Pichu
RIP PICHU.
(adsbygoogle = window.adsbygoogle || []).push({}); The way you write your code can be the difference between seconds, minutes, and hours for processing.

Below, I have an image showing the results of multiple tests, the tests showed on my computer roughly the exact same so I only select one result from each source as a median.

As you can see, just a little change in code has affected the speed of the application by several seconds. Not much but if used in the real world throughout the day, 7 seconds in an hour based upon the normal time this application takes, that's 140 seconds in an hour or 2 minutes and 20 seconds wasted. In a day, that's over half an hour.
You must login or register to view this content.
(adsbygoogle = window.adsbygoogle || []).push({});
05-16-2013, 02:00 AM #11
Pichu
RIP PICHU.
Originally posted by another user
It's easier and more efficient to keep manipulating one object.


Right there is the definition of Object Oriented Programming.

---------- Post added at 07:00 PM ---------- Previous post was at 06:58 PM ----------

Originally posted by Killer1478 View Post
Yeah but neater code =/= easy to read. To anyone new who doesn't understand objects can be used in that method, might get confused. But its all theories.


The code itself can be neat or clean; cleaner code is much easier to read than messy code. Also, there is a such thing as commenting your code so the person reading what you have done, or even yourself, can know what is going on from actual language.

A person who knows their code will have a lot easier time reading code than a person who does not.
05-16-2013, 02:32 AM #12
TheQuagmire
Bounty hunter
Or you could like have a faster computer and those seconds won't even be there. Giggity.
05-16-2013, 02:50 AM #13
Originally posted by Master
The fact is, you shouldn't instantiate new objects in code blocks. It just creates more work for the destructor. It's easier and more efficient to keep manipulating one object.


Like I said though, sometimes its necessary. Say for multi-threading and you want multiple downloaders going on at once, for example's sake lets say you use the WebClient, using one webclient in multiple threads causes an overload and would cancel out works done by other threads. If you make the program dynamic you cannot pre-define all the webclients (well you kind of can but lets say you can't) my example is falling awkwardly but, you don't even need to wait for the garbadge catcher, you can simply create new and then dispose when you're done with it at the end of the loop, or you can call the garbadge catcher to do so itself.

All im saying is sometimes it might be the easier solution though its a weird example that I used. q-q

Originally posted by Pichu View Post
Right there is the definition of Object Oriented Programming.

---------- Post added at 07:00 PM ---------- Previous post was at 06:58 PM ----------



The code itself can be neat or clean; cleaner code is much easier to read than messy code. Also, there is a such thing as commenting your code so the person reading what you have done, or even yourself, can know what is going on from actual language.

A person who knows their code will have a lot easier time reading code than a person who does not.


Well, I learned almost everything I know from studying old sources but lets say I see

Excuse any syntax errors, I wrote this from scrap.
    
System.net.Webclient x = new System.net.Webclient();
String data = null;
data = x.DownloadString("https://google.com/text.txt");


I can easily break that down. First we declare a new webclient, then a new string, then we use our webclient to download strings and put them in our string.

Where as
    
String data = new System.Net.WebClient().DownloadString("https://google.com/text.txt");


We both understand this but, someone new probably would be slightly confused.
I'm not saying we need to dumb down code, but its just in my personal history I'd prefer to read it in the first method that I posted compared to the second one.

Originally posted by TheQuagmire View Post
Or you could like have a faster computer and those seconds won't even be there. Giggity.


It'll still be there no matter how fast your computer.
05-16-2013, 03:00 AM #14
TheQuagmire
Bounty hunter
Still be there even though You must login or register to view this content.? That makes zero sense bro.
05-16-2013, 03:12 AM #15
Pichu
RIP PICHU.
Originally posted by Killer1478 View Post
Like I said though, sometimes its necessary. Say for multi-threading and you want multiple downloaders going on at once, for example's sake lets say you use the WebClient, using one webclient in multiple threads causes an overload and would cancel out works done by other threads. If you make the program dynamic you cannot pre-define all the webclients (well you kind of can but lets say you can't) my example is falling awkwardly but, you don't even need to wait for the garbadge catcher, you can simply create new and then dispose when you're done with it at the end of the loop, or you can call the garbadge catcher to do so itself.

All im saying is sometimes it might be the easier solution though its a weird example that I used. q-q



Well, I learned almost everything I know from studying old sources but lets say I see

Excuse any syntax errors, I wrote this from scrap.
    
System.net.Webclient x = new System.net.Webclient();
String data = null;
data = x.DownloadString("https://google.com/text.txt");


I can easily break that down. First we declare a new webclient, then a new string, then we use our webclient to download strings and put them in our string.

Where as
    
String data = new System.Net.WebClient().DownloadString("https://google.com/text.txt");


We both understand this but, someone new probably would be slightly confused.
I'm not saying we need to dumb down code, but its just in my personal history I'd prefer to read it in the first method that I posted compared to the second one.


Yea, I agree with you there. To be honest, if I knew I was going to have to use an object multiple times, it's going to be better for me to just create the object once and then use it.

If however I was only using it for a single instance and then never would have to deal with that again, I'd probably go my second option.

It's situational for me.

---------- Post added at 08:12 PM ---------- Previous post was at 08:11 PM ----------

Originally posted by TheQuagmire View Post
Still be there even though You must login or register to view this content.? That makes zero sense bro.


What the fuck are you even saying?
05-16-2013, 03:19 AM #16
Originally posted by TheQuagmire View Post
Still be there even though You must login or register to view this content.? That makes zero sense bro.


No matter how fast you get, running more instructions will always create a delay.

To simplify this, take a string and hang a weight from it, it sags right?
Take a thicker string and hang the same weight from it, still sags but less right?
No matter how how thick you go, the string will always sag even if its just very slightly.

Same thing with computers. Add more work, and no matter how fast the computer it will always have somewhat of a delay. It will never be 0.

(There is a very very long winded method to explain why but I won't do so.)
05-16-2013, 03:20 AM #17
TheQuagmire
Bounty hunter
I don't know what kinds of crops you've been dusting flyboy, but a system that's optimized for compiling would not see those timings appear. Especially if you have access to a farm that compiles the source. So by saying bullshit like a faster computer wouldn't see a difference in compile times is about the stupidest thing I've heard this week.
05-16-2013, 03:31 AM #18
Originally posted by Pichu View Post
The way you write your code can be the difference between seconds, minutes, and hours for processing.

Below, I have an image showing the results of multiple tests, the tests showed on my computer roughly the exact same so I only select one result from each source as a median.

As you can see, just a little change in code has affected the speed of the application by several seconds. Not much but if used in the real world throughout the day, 7 seconds in an hour based upon the normal time this application takes, that's 140 seconds in an hour or 2 minutes and 20 seconds wasted. In a day, that's over half an hour.
You must login or register to view this content.



Well no shit it will take faster! lol

In one you are allocating a whole new object into memory over 1000 times (or however many were in your loop) where as the first one allocates the object once in memory and then computes based on that object only once ;0
05-16-2013, 03:34 AM #19
Pichu
RIP PICHU.
Originally posted by Killer1478 View Post
No matter how fast you get, running more instructions will always create a delay.

To simplify this, take a string and hang a weight from it, it sags right?
Take a thicker string and hang the same weight from it, still sags but less right?
No matter how how thick you go, the string will always sag even if its just very slightly.

Same thing with computers. Add more work, and no matter how fast the computer it will always have somewhat of a delay. It will never be 0.

(There is a very very long winded method to explain why but I won't do so.)


Example. if a computer has to process for 1 more second than needed, that one second; if running 24/7 in 28 days of time will take:

If the program takes 10 minutes to work, 1 extra second; 6 seconds an hour, 144 seconds a day. (2 minutes 24 seconds).

144 * 28 days = 4032 seconds = 67.2 minutes of extra processing in 28 days of 24/7 processing.

That means that the program could have been ran nearly 7 more times but the code was hanging for an extra second.

---------- Post added at 08:34 PM ---------- Previous post was at 08:32 PM ----------

Originally posted by Jake625 View Post
Well no shit it will take faster! lol

In one you are allocating a whole new object into memory over 1000 times (or however many were in your loop) where as the first one allocates the object once in memory and then computes based on that object only once ;0


Well no shit, the fucking objective of this thread was to point out that the way your code matters. No explanation needed.

Winky Winky

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo