Some basic tips for newer programmers when it comes to optimizing your code for speed. learn programming |
- Some basic tips for newer programmers when it comes to optimizing your code for speed.
- How are you able to juggle learning programming and life responsibilities?
- Just built my first program and used it effectively at work!
- Top 100 data science courses, sharing my curated list
- 8 tips for computer science students
- Is there any community that supports for SQL and Python issues?
- What's with people knowing how to code at so young?
- How can I implement a html/javascript front to my python backend?
- Syntax error on print for Python
- Need help sending data from Arduino to MIT App Inventor
- What software do I need for Python ?
- Junior Web Dev in a large project Help & Tips Needed
- Got accepted into a year long coding program designed to fill the needs that aren't met in my area (coding/programming)
- I'm not sure if this exists, but I was hoping I could find it here. Are there any beginner/intermediate Python projects where they give you an idea of where to start and nudge you in the right direction without giving the answer in a step by step manner?
- Need some help creating a bot/script
- Learning WebAssembly and benchmarking performance
- Anything wrong with leaning two programming languages at once?
- Need some help with beginning Python
- Is Being Good At Math A Requirement For Pursuing A Computer Science Degree?
- Find all subsets of length K in racket.
- I want to learn and work in artificial intelligence not deep learning, help?
- What’s the best language to parse pdf files and extract data that will be imported to excel?
- What type of job should I be looking for?
- Learn C++ GitHub Repo!
- Are there any similaties between ER and Dimensional modeling?
Some basic tips for newer programmers when it comes to optimizing your code for speed. Posted: 26 Feb 2019 11:37 AM PST As someone who works in a field where squeezing every last bit of efficiency out of your code. Speed optimization is a pretty important for me. I work in computational physics where I am often working with molecular dynamics, monte carlo, etc. codes that can run for hours using up a 200 CPU cores in a single job. Thus for me 1% inefficiencies are measured in terms of hours. I originally told some of these tips in a more verbal format to some newer physics students, but I thought posting a shorter text version of would be good for some newer programmers. 1. Make sure you need optimization in the first place. A common mistake among beginners is that they attempt to optimize a piece of code when they really don't need to. A general rule of thumb. Speed optimization only becomes important when the time it takes to write the code is much smaller than the time it takes to run the code. When it's the other way around, then comprehensive speed optimization is generally not required and at that point you should prioritize readability, simplicity, and good code organization more than optimization. It doesn't matter if it takes 2ms vs 1ms to run your Python script if you are only going to use it a few times. You could use the script 10,000 times a day and that optimization will only save you 3560 seconds a year (About an hour) in the long run. So if it takes you more than an hour to make said optimization, it isn't worth it. Typically if your total run time is in the range of seconds or less don't worry. Now if it is in the range hours, days, weeks, etc. then it can be worth it. That's where a lot of my codes land and thus optimization is important for me. An exception might be if you are writing code for something that must complete it's job within a specific amount of time in order to function properly. For example micro-controler programming might be an area this can be important. 2. Learn your profiler tools This will vary depending on which language you use, but pretty much all of the modern programming languages have some some sort of profiling tool or compiler options that allow you to figure out how smoothly your code is running. Compiled languages for example often have compiler flags you can use to output time analytics. This will tell you where the bottle necks are which is important to actually improving run times. Always keep in mind. If a part of the code consumes 20% of the total run time of the program, then optimizing that part of the code will generally give you at best a 20% speed up. Though in practice it is often a much lower return than that since 100% optimization isn't always possible. So make sure to focus on the most time consuming parts first. If no part of the code is particularly more time consuming than the other then optimization may not be feasible or at least not easy to do. 3. Learn your language specific optimization tools. So if you get through 1 and 2 and realize you do indeed need to optimize your code. The next step is to first ensure you are using the common tools that are easily available to you. These are often libraries that can perform common tasks using well written algorithms. These are usually much better than you can probably come up with on your own since in many cases it is written by people who study these things for a living. Compiled languages usually have optimization flags at compile time, Python has libraries such as Numpy to help speed up certain operations, etc. For common operations like matrix opperations common libraries like BLAS, LAPACK, etc. can be helpful. Your language's standard library can have a lot of useful tools for things like sorting arrays or performing search opperations. In addition if you are working with languages that allow you to manage your memory. Learning things such as matrix ordering (IE Row Major vs Column Major) can give massive speed ups. For example in many C languages they have a row major ordering. IE this is often faster than this Where as in other languages (Fortran for example) it is inverted. This has to do with how memory is physically stored and sent to your processor's cache on your computer. If you are working with a language where you have to manually manage your memory, learning these practices can be helpful. 4. Macro before Micro. Now let's say you get through the easy premade optimization tools and still want to squeeze more out of your code. The next thing to do is to ensure that before you start doing small optimizations, you first ensure you are writing the most efficient algorithms to begin with. An example of a micro change might be something like changing to This can give a small speed up sometimes if the compiler or interpreter doesn't substitute the exponent function with multiplication (a cheaper operation), but in practice it's usually only a little bit of a speed up. The best way to improve speed is to improve your algorithm at a macro level first and making sure you aren't performing unnecessary calculations. For example, let's say you need to compute the distances between thousands of points which is common in physics engines. You could simply write a loop such as this Which would indeed give you all the distance pairs in the system. However this naive way of doing it is not very good for a huge number of objects. This naive algorithm grows at a rate of O(N2 ) and thus will blow up in your face the more objects you have. If you only care about say a situation where two objects smash into each other (game physics for example) then you only need to care when the distances are small enough to cause a collision. If the objects will only interact if they get within a few meters of each other, then it makes little sense to be computing distances when the two objects at several hundred kilometers away from each other. Instead you might use an algorithm like a cell list. https://en.wikipedia.org/wiki/Cell_lists Which goes through and assigns each object to a bin based on their location in the world (an O(N) operation) and then you only need to compute the distances of the objects that are in the same bin or in neighboring bins. This gives a run time that is closer to O(NxM) where M is the number of objects inside of a bin which is usually much much smaller than N. These algorithms perform exceptionally well when the world is sparse (IE most objects are scattered across a large area) and there's even more fancy ones you can find for your purpose. Plus if you know that an object isn't going to leave a bin in the next set of calculations (Example a car isn't going fast enough to exit one bin in a single frame.) you only need to update the list periodically instead of every step. In general picking better algorithms at a macro level will net the best results in efficiency than making micro-optimizations. Efficiency is like playing a game of golf. You are trying to find the best way to the cup in the least amount of strokes. 5. All else fails, look into parallelization if applicable Creating parallel codes is another option to improve performance if improving single threaded performance is a dead end for you. This can be a pretty open ended study so I probably won't go into too much detail here, but common libraries such as MPI, OpenMP, CUDA, and also the various language specific platforms can help you run your job across multiple threads. If you are in need of some serious performance, looking into how to use that expensive GPU you got or that 32 core threadripper in your computer can be helpful. Be warned though, it is a lot more intensive to learn how to write good parallel code. But the flip side is also there are job positions for people who are experts in it. So it can be good to have on a resume. 6. It's ok to make micro optimizations, but don't do so at the cost of making your code completely unreadable Even in highly optimized codes, readability is still important. When making more minor changes always make sure you can still read the code at the end of the day and also make sure the micro changes actually give a good speed up. Sometimes what you might think will improve the speed of the code doesn't because the interpreter/compiler does things behind the scene you didn't know about. Always check and compare speeds for any changes you make. Plus make sure you do so in a statistical manner (IE run it more than once and get a good average) Making an optimal mess should be avoided unless there simply is no other way. Which in my experience, is rare. Plus always remember, if writing the code is consuming more time than the time saved running the code then it probably isn't worth it. At the end of the day the whole purpose of speeding up your code is to save time. But you aren't saving time if you are wasting it writing the code! Hope that helps. (Edit: Removing some redundant points) [link] [comments] |
How are you able to juggle learning programming and life responsibilities? Posted: 26 Feb 2019 03:34 AM PST I haven't done any coding within the past two weeks because there is always something to do. Yes I work full time, I am applying to jobs almost every couple of hours per day and making sure I get some rest...not saying I'm a full time productive workaholic saint because I do have 3-4 off days to relax and I reddit a lot [link] [comments] |
Just built my first program and used it effectively at work! Posted: 26 Feb 2019 06:07 PM PST I'm an adjunct professor teaching governmental finance. Fun! So to spruce it up a bit I decided to create an activity where my students are given policy objectives and then have to deliberate on a budget. The winner gets extra credit. I created a scorecard and integrated it into a python budget that let me analyze the budget in real time. So my students got to see how the scoring worked and everything. they loved it! The code is completely just brute force and messy. But it works and it's mine. Best feeling ever. Somewhat related : is this the type of thing I put on my github? Still trying to figure that site out. [link] [comments] |
Top 100 data science courses, sharing my curated list Posted: 26 Feb 2019 02:32 PM PST Hi, Sharing my curated list of free and free trial list of best data science courses available online. Hope this helps anyone looking to get started in data science and seeking an introduction! Let me know if you have any more suggestions. Thanks Pankaj [link] [comments] |
8 tips for computer science students Posted: 26 Feb 2019 05:53 PM PST I am finishing up my final semester of my computer science degree and I decided to make a list of tips that I would give to future students. https://renaissancemanhq.com/top-7-tips-for-computer-science-students/ [link] [comments] |
Is there any community that supports for SQL and Python issues? Posted: 26 Feb 2019 11:03 PM PST Is there any community/subreddit that supports its users in SQL and Python issues? [link] [comments] |
What's with people knowing how to code at so young? Posted: 26 Feb 2019 01:34 PM PST I've seen people on the Internet who claim to be 16 year olds and know ASM. Back when Miiverse was a thing I knew a guy around 13 who cloned the entire site in PHP. Like, HOW? Do their parents start teaching them programming at the age of 6? I don't get it! I'm 18 and I barely know NodeJS. [link] [comments] |
How can I implement a html/javascript front to my python backend? Posted: 26 Feb 2019 04:06 PM PST I have tried googling it and nothing really showed how it works or how to properly implement it. ateast not enough to where i can also understand why and how it works thank you [link] [comments] |
Syntax error on print for Python Posted: 26 Feb 2019 09:04 PM PST Any idea why I am getting a syntax error for below? word = input("What do you want me to say? ") number = int(input("How many times shall I say it?" ) print(word\number)* Expecting the output to be a word repeated n number of times but I get this error File "program.py", line 3 print(word\number)* ^ SyntaxError: invalid syntax Have tried putting a space, an = sign, and even changing the last line of code to just print("Hi") but it still has the error. Am very very new to coding so please don't be too harsh on me if this is a super easy fix - have tried to find the solution myself but not sure at all on this. [link] [comments] |
Need help sending data from Arduino to MIT App Inventor Posted: 26 Feb 2019 04:37 PM PST I'm trying to connect my arduino bluetooth sensor to an MIT App Inventor app I made, and in doing so display the readings of two of my sensors. Whenever I test the sensors in the serial monitor, I get normal readings, but sending them to MIT APP Inventor makes them glitch out and give me the error "Select list item: Attempt to get item number 2 of a list of length 1". I've reviewed all of my code for both the Arduino and the MIT App Inventor (especially the parts with lists), and I haven't been able to find anything that may be hindering me. The timer interval for the MIT App inventor code is correct. I've placed my Arduino code below, and the MIT App Inventor block code in this link. EDIT: This is probably a bit pathetic, but this is pretty urgent (due tomorrow) so I'd like to get this fixed as soon as I can. I thank anyone who'll try to help 1000x in advance, and I'll probably thank you more if you reply. [link] [comments] |
What software do I need for Python ? Posted: 27 Feb 2019 12:02 AM PST I recently purchased a Python beginners book to learn Python but it hasn't been delivered yet. What software will I need to download or buy ? [link] [comments] |
Junior Web Dev in a large project Help & Tips Needed Posted: 27 Feb 2019 12:01 AM PST Hey everyone, I am not sure if this is the right place, tried going through the FAQ so please let me know if I need to submit this elsewhere. With that out of the way, please bear with me to explain you the situation I am in: I am working in a large company, as a technical but not dev position. I am now trying to transition myself into a junior web dev - I graduated one course, doing a ton of e-learning in udemy and front end masters. I received support from my superiors on this decision. I have now access to the code and working on very small fixes. Problem is that I only worked on small project - like 5-6 pages and having such an incredibly vast project now feels overwhelming. I didn't know much about version control, found cherry-pick in the last second, having troubles even finding the file I need to work on, they are that many. My question is, do you have any tips and trick for early beginners like me? Are there a must know things, good practises, literally anything in terms of advice and resources that could make me a better developer and a colleague? Thank you a lot to anyone that takes the time to read & help here! [link] [comments] |
Posted: 26 Feb 2019 11:58 PM PST I used to try to teach myself coding but at a point it got too hard and I gave up. I aced the coding portion of my test/essay and got accepted. They just started this program in my area. They started the program specifically to fill in coding jobs that weren't being met in my area. I am very excited because this is something I'm passionate about. I have been working my butt off to save money for the tuition. That isn't why I'm here. I'm here to see if anyone has any similar experience. And if this whole thing doesn't work out, I will teach myself. Any advice or tips would be appreciated. The school I'm going to attend says at the end they will help you get a job, which is filling in the demand that's not being met from what I'm told. [link] [comments] |
Posted: 26 Feb 2019 09:50 AM PST I'm looking for something like if you want to build X, then you should import libraries Y and Z and perhaps use some of these techniques. I have a minor in CS and I got an A in all my CS classes, so I know the basics pretty well. I just am a learn by doing person, so I just want to go and build some stuff and learn by error but also get a little help if I need it without them just giving me step by step answers. I wouldn't mind if they have an example of how they solved it in the end so I can compare my code once it's completed. I need to learn Python for my job so I need to get on this ASAP. I just finished a basic Python book, so I'm ready to start building. [link] [comments] |
Need some help creating a bot/script Posted: 26 Feb 2019 11:10 PM PST |
Learning WebAssembly and benchmarking performance Posted: 26 Feb 2019 10:48 PM PST I've been trying to wrangle with WebAssembly and understand performance benchmark possibly against JS. Came across this article, wondering if anyone around here had any experience with WebAssembly and performance comparisons.. https://medium.com/wasmer/running-webassembly-100x-faster-%EF%B8%8F-a8237e9a372d [link] [comments] |
Anything wrong with leaning two programming languages at once? Posted: 26 Feb 2019 06:53 PM PST Greeting. I would like to get into website and game development. I started my learning both HTML and CSS. I consider myself fluent in both languages. I progressed to learning JavaScript, and then started in c++. So far feel alright leaning both at once, and feel like I am able to take it. Is this generally considered a bad idea, or is it ok? Thanks, - Riley [link] [comments] |
Need some help with beginning Python Posted: 26 Feb 2019 10:31 PM PST Hi! First post on here so I apologize if this post isn't allowed. I just started Al Siegwarts book Automate the Boring Stuff With Python based on recommendations I saw on this subreddit. My biggest problem isn't learning syntax so far, but it is how to apply it. I can remember the basics of how functions and modules work but I can't find any ways to practice or truly learn. I learn by practicing and I really need some help getting a jump start into programming for the first time. If anyone has any recommended Python resources for very new beginners then let me know please! I am dying to learn as much as I can I just need help getting a jump start. [link] [comments] |
Is Being Good At Math A Requirement For Pursuing A Computer Science Degree? Posted: 26 Feb 2019 10:28 PM PST Most websites say that a Computer Science degree is good if you have a strong math background. I am competent when it comes to programming but terrible at math. I barely made it though pre-calculus in High School and required a bunch of tutoring. It takes me much longer to understand simple math concepts and I require a lot of extra help. Would it be better to pursue a different option that is less math intensive, where I would still learn what I need to become a Software Developer? I'm interested in getting a Computer Science degree because of the extra opportunities it opens up and because I'll get to specialize. If I do try the CompSci route I'm worried that I'll never make it through Calculus or any of the higher level math courses like Statistics and Linear Algebra. [link] [comments] |
Find all subsets of length K in racket. Posted: 26 Feb 2019 12:36 PM PST Hi,so,I need to find all subsets of length k in a set,for example : from (1 2 3) you get (1 2) (1 3) (2 3). I wrote this code in racket but it doesn't work,it only shows the first subset it encounters ( (2 1) for the above example ) "images" is the whole set,"k" is the length,"subsets" is a list of lists where I save every subset and "subsetList" is the current subset. My logic is this:
My guess is it stops at the second condition somehow but I don't get how to stop the program properly. [link] [comments] |
I want to learn and work in artificial intelligence not deep learning, help? Posted: 26 Feb 2019 06:31 PM PST I am a 30 yr old man who is currently a hardware technician. I've been studying computer science at my local community college and am ready to start working on my bachelors. I noticed a lot of courses that say intro to artificial intelligence really comes down to machine learning , deep learning, math and algorithms which is cool but I would like to work in general intelligence like the Sophia project. What should I study or work in to try and reach that kind of goal? [link] [comments] |
What’s the best language to parse pdf files and extract data that will be imported to excel? Posted: 26 Feb 2019 10:04 PM PST One of my friends wants me to come up with a desktop application that will allow him to choose multiple pdf files and read data from the first two rows and import the values to an excel spreadsheet? I have worked with C# before and was thinking of using that but I'm wondering if there are better languages that can do this better. Thanks. [link] [comments] |
What type of job should I be looking for? Posted: 26 Feb 2019 01:00 PM PST I have 2 years of classes from colleges so I have a good knowledge of data structures, software engineering process or life cycle or what have you, and about 6 years experience in java so i have a good grasp on OOP, 2 in C and basic understanding of C++ (a small arduino project i worked on that had led lights react to music). But on the other hand I have more recently been working with installing operating systems (I use Arch btw ooo) which i feel i have sufficient knowledge over. I also have basic understanding of webservers and databases (set up LAMP on raspberry pi with some fucky little php files to say hello world and what not) but ultimately i have limited experience in html and php itself. My question is I guess, I'm on so may different routes it seems for just "computer science" in general, which should i be focusing on? [link] [comments] |
Posted: 26 Feb 2019 09:43 PM PST Howdy, Sonny from Codecademy! Just created our first public repo for a course. 🙂 Feel free to add to it: https://github.com/Codecademy/learn-cpp [link] [comments] |
Are there any similaties between ER and Dimensional modeling? Posted: 26 Feb 2019 09:39 PM PST Trying to compare ER modelling and Dimensional modeling for data warehouses. Any information and sources would be very helpful. [link] [comments] |
You are subscribed to email updates from learn programming. To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google, 1600 Amphitheatre Parkway, Mountain View, CA 94043, United States |
No comments:
Post a Comment