Posts tagged ‘dualcore’

Python - Not Quite Perfect … But Darn Good

For the last few years I’ve been working heavily in the Python programming language. It’s an absolutely wonderful language and I do love it so. Besides forcing good indentation practices and being otherwise good with whitespace, it also is a wonderfully clever little language with many neat tricks that a seasoned programmer can appreciate.

However, it’s not all sunshine and lollipops.

For being an interpreted language, most of it runs quite fast. And where its speed does fail, there’s always writing libraries in C++ and then wrapping it in Python to use in your Python code. So most of the time it has a wonderful performance if you know what you’re doing.

Just recently though, while working on some string code to remove ASCII characters 128-255 from strings, as these beyond-standard-ASCII characters don’t translate to Unicode, I am reminded of one of Pythons massive failings. It handles strings for sh_t.

Don’t get me wrong. Python has all sorts of neat methods and functions for string manipulation. It’s quite handy really. But it’s s…l…o…w. Something about the way that Python assigns a new string variable is just darn slow. And nearly every string operation requires you to assign a new string variable as each function / method returns a string that is your results. So when all of your functions return a new string, and creating new strings in Python is slow … you see how this is a very bad combination.

For example, the code I was working on. A really neat Pythonic way of doing things results in the function:

def stripBadASCII1(contents):
    if not contents: return contents
    return “”.join([c for c in contents if ord(c) < 128])

This strange looking code goes through contents character by character and only joins the characters below ASCII 128 to the returned string. Simple. Neat. Effective. But keep in mind, the way Python works, for each new character joined to the string, it has to create a whole new string. And in Python this is molasses in January slow.

Now another method, a little more mundane in concept, goes like this:

def stripBadASCII2(contents):
    if not contents: return contents
    for i in range(128,256):
        contents = contents.replace(chr(i), “”)
    return contents

You see, the concept of this one is easier to follow. It replaces all bad ASCII characters in the string with an empty string, which effectively strips those characters from the string. Looping 128 times through the string for each bad ASCII character. Ugly. Messy. And yet, because it moves string contents in chunks instead of character by character, the number of new string operations is greatly reduced. So even though it loops 128 times through, where as the other function only executes once, it still manages to run faster for all of its seemingly slow 128 loops.

When I ran function 1, the character by character approach, through the contents of a test file typically used in the code this function is being written for, on average it took about 0.1 seconds.

When I ran function 2 through the same contents, using the seemingly slower 128 loop approach, it took on average 0.06 seconds.

Okay, so four hundredths of a second doesn’t seem like much of a difference. But the longer the string processed through these functions, the larger that difference will get. And more to the point, this my friends is how bad Python is at handling strings. A single pass through, character by character, is almost twice as slow as 128 loops through with chunks of characters processed together. Ouch. This certainly isn’t the C++ approach to strings.

So that’s one of Python’s major failings, is it’s string handling performance. Python has another major performance failing as well. Even though it can create and manage threads, it doesn’t ever use more than one processor. So if you have a multi-core CPU, you only use one core. If you have a multi-processor PC, it only uses one processor. If you have a dual CPU quadcore PC with a total of eight cores, it still runs on just one core of one processor. No matter how many threads your Python code contains. Ouch!

In fact, because of the overhead of thread management, and because it only runs on one CPU, Python actually runs slower the more threads you give it to handle. Yikes!

In the old days when multi-CPU computers were rare and multiple cores per CPU was unheard of, this was not a problem. Today is not those old days. Today two, three, and four core CPUs are common for desktops. Heck, I just built my hun’s new budget computer with a dualcore Celeron. So more than anything, this is really an issue Python needs to fix, and soon. They’ve put this one off far too long already.

A workaround is to try and develop your code as multi-process not multi-threaded. Or in other words break the program down into independent sub-programs that the main program can spawn as needed. There are memory sharing techniques that can be used for inter-process communication. It’s ugly. It’s messy. But being independent Python processes, they should spread across multiple CPUs/cores like a normal multi-threaded program would. Still, it’s very far from an ideal solution. It is just another messy workaround.

So that, my friends, is the down side of Python. It’s a wonderful language, but no language is perfect. They each have their own strengths and weaknesses, and Python is no exception.

Geek PC Building Alert! My Hun’s New Computer…

So as I said, I’d given Newegg one last chance as I ordered a bunch of parts to build my hun a new computer. While my experience with Newegg was yet again a flop, at least my experience in speccing and building computers wasn’t. So here’s a whirlwind tour of the building of my hun’s new PC.

Case: Raidmax Apex big mofo black case with 450W PSU

Cooling: one intake 120mm fan, one exhaust 120mm fan, side CPU vent

CPU: Intel Celeron E1200 dualcore 1.6GHz based on the Core2 design

Motherboard: Biostar GF7100P-M7S micro ATX, nVidia chipset, onboard graphics /sound /LAN

Graphics: Onboard nVidia 7100

Memory: 2 Gigabytes Wintec AmpX DDR2-800 (PC2 6400) set to 4-4-4-12 timings

Hard drive: Seagate Barracuda 160GB 7200RPM SATA 3.0Gb/s with 5 year warranty

Optical drive: Asus DVD+/-RW with LightScribe bundled with Nero 7 Essentials

Operating System: Windows XP Home SP2

Additionals: 1.44MB floppy, Logitech X-140 speakers, MS Office Home and Student

As you can see, it’s a budget home-office build PC. It doesn’t have many frills because the only gaming it will see are Spider Solitaire and Vegas Slots. But it can run nasty Excel spreadsheets and Word documents while surfing the web and playing music quite well. And with its oversized power supply, exceptional cooling, and moderate performance it is more than ready to stand the test of time and be upgradeable when or if it needs more.

You’ll also note that I stayed away from Windows Vista because I wanted my hun to have a computer that actually works and has drivers for all of her hardware.

So how did the build go?

Anti-static protection is important!

Before we start, let me point out one of the first basic rules of building a computer: Zapping the parts with static electricity is bad. That’s why a fashion accessory like this lovely sky-blue wrist strap not only looks stunning, but it also protects your sensitive parts from being stunned. I never build a computer without anti-static protection.

Okay, enough of that. Now let’s start.

Look!  It's a menagerie of parts!

Here we have a menagerie of parts. Yes it looks like a lot of stuff to cram into that computer case. But actually, compared to years ago, it’s not that much. With the graphics, sound, and networking all built into the motherboard (and almost no one using internal 56K modems these days) there’s really not much that you need to add to it, at least when doing an office-type computer like this one. (Gaming computers need more graphics power at the very least.) And for the most part, things are pretty idiot proof these days. Parts and cables only fit in one way. You no longer have to remember details like pin1 typically points towards the power and things like that. Heck, the back panel on a computer and the external cables are usually even color-coded so that you’d really have to not be paying attention to get it wrong. It’s nice to see improvements in the simple things. Computers today are so much easier to work on than in the old days.

Strip down that case!

So we start taking crap out of the box. First thing I do is open up the case. You’ve got to put things in there, so you might as well get it ready then. And since this is a budget case without any luxuries of drive slide trays, quick mounts, etc. that means we have to take off not just the normal access panel, but also the back panel so that we can screw in the drives from the other side as well. A minor inconvenience - but also a little nostalgic.

Adding a 120mm intake fan.

Yes, I happened to have an old 120mm case fan from Antec from long ago. I added it as an intake fan since this case just happened to have a 120mm fan mount there. When you’re a geek, being a packrat can have some advantages. Now the more than adequate cooling of the 120mm rear exhaust fan is absolutely stellar with this added 120mm intake fan. For a budget office PC you don’t get much better than this. Why does it matter? Well electronics really aren’t partial to heat, and keeping them cool should grant them a longer lifespan as well as keep anything from getting flaky.

Insert drives to continue...

Insert drives to continue… It sounds silly, but with cheap cases sometimes one of the biggest pains in the butt is getting the darn drives into their respective bays. Sometimes you even have to bend the metal of the case a little bit to get them in. So, I decided to get that part out of the way before any real electronics were inside. Because on extremely rare occasions I’ve had to dremel a bit and the last thing you want on your motherboard are steel shavings.

Back in black!

Back in black! In computers, black is the new beige. Which in my opinion is just peachy-keen fine with me! So now that the drives fit into the steel part of the case, let’s try it again with the plastic front bezel on as well, since (especially in cheap cases) the plastic doesn’t always match up to the metal and you can have a mighty tough fit. Which was what happened in this case. But fortunately a tweaking with a set of pliers was all that was needed to get that DVD drive to finally slide in all the way. Yipee! It’s a fit. And I might add it looks rather good as well.

Installing the motherboard standoffs.

Next up is one of the biggest pains in building a computer: installing the motherboard standoffs. You see motherboards have little holes in them to screw them down onto the case. (Or if you’re really lucky, a removable motherboard tray in the case.) I’ve seen plastic standoffs used, but mostly I just see brass these days, which I prefer. Now even though we have things like ATX and micro-ATX standards, cases typically don’t have standoffs pre-set. No, you’ve got to play match the holes and then screw in the darned standoffs yourself. And you want to make sure to screw them in tight, because you are going to set a screw into them when all is said and done and you want those screws to come out freely should you need to remove the motherboard again. Fun fun.

Hey!  Look!  A mobo!

So now that the case has the motherboard standoffs installed, let’s double-check that they’re right by putting on the motherboard. Depending on the CPU heatsink, or tight fight cabling situations, you may want to wait on installing the motherboard into the case until after you’ve taken care of those tricky problems. For example, because my heatsink required a certain amount of pressure, I actually took the motherboard back off while installing it so that I didn’t cause any bending in the motherboard as I installed the heatsink. But after installing the standoffs you still always want to double-check that you’ve installed them correctly.

Feed me!  It's a hungry CPU socket!

Hungry Hungry Hippo? No, that’s a hungry CPU socket. Intel is notorious for having a new CPU socket to go with each new generation of processors, and once again they do not disappoint. This new LGA or Land Grid Array socket mechanism is certainly interesting. No longer do you have all manner of little pins sticking out of your processor. Now you have a flat processor and all sorts of little pins sticking out of the motherboard. Okay. Whatever. At least it’s not a ZIF (Zero Insertion Force) socket anymore. This one really holds down that CPU quite well.

That CPU is a perfect fit!

It’s a perfect fit! The CPU goes into the socket quite nicely. It’s quite a relief really. The CPU is typically the part that computer enthusiasts worry about mostly. You really don’t want to break it, you know? It sounds funny to say, but it wasn’t long ago when it wasn’t always so clear-cut which way was “up”, and bent pins could really add a lot of trouble. Where as this, as the brits say, is easy as chips.

Placing the heatsink on is cool.  Sort of.

It’s cool, the heatsink is in. Okay, so it wasn’t actually all that cool. Of all of the heastsinks that I have ever installed, this is the second worst I’ve had to do. (The worst being a gigantic passive no-fan heatsink on an overclocked P4 Northwood C that was held down more by mounting bracket pressure than anything, so it was easy to slide around and hard to position “just right”.) This stock heatsink from Intel is crap to mount. You push down the pin at each of the four corners. And it’s supposed to lock into place. Except it doesn’t always just click-lock-stay. Sometimes it kind of stays until you do the next one and it pops back up. You’re afraid to push too hard because you don’t want to break anything. But with this stupid stock heatsink it’s really a push-and-pray brute force attack. It’s on now. And it’s stayed on moving it around a bit. But I sure wouldn’t trust that thing during shipping. If I was going to sell a PC like this to a customer, I’d definitely look into a non-stock heatsink that holds down better because I really can’t swear that thing will stay on even just going into a car trunk and back out. It scares me. I’m also not convinced by the cute little design of three separate TIM (Thermal Interface Material) shapes on the heatsink instead of just a simple single layer of TIM. It seems to be working, but it was not comforting. Intel, you really f____d up here. Stock heatsinks should not scare system builders this much. Things used to be so much better…

Thanks for the memories.

Thanks for the memories! So I took a little risk and went with a memory company I’ve never heard great things from, Wintec. But their AmpX line looked like a nice little rebranded stick with a heatspreader added. It’s a cheap trick that us geeks used to do on our own, but now so many companies are doing for us. (Opposed to the good professional jobs done by quality companies where you know they’ll hold up well.) The official timings from Wintec are 4-4-4-12. But of course the motherboard reads the programmed SPD as 5-5-5-15. Definitely not a pro job there. But hey, 4-4-4-12 is what the manufacturer rated it at, so (later) I manually set it to that in BIOS. And it works just fine. It’s what it’s warrantied at, and it works at it, so all is good.

I've got those front panel blues.

Now that the main bits and bobs are installed on the motherboard, it’s time for the next most annoying part of building a computer, those front panel blues. Why we can’t standardize those + and - pins from the hard drive light, power light, power switch, reset switch, etc. is beyond me. Sometimes you get lucky at least and the front panel audio connector is a solid block. Same with USB. And sometimes you have to fiddle with it all pin by bloody little pin. Because it’d kill the industry to just have one damn big block that does it all. Just a standard audio, two USB ports, power light and switch, reset switch, HDD light, and piezo PC speaker. And then have the rest (like additional USB, audio, or Firewire ports) all willy-nilly. I just don’t get it. But at least in this case the audio and USB were solid blocks. But it was still a pain in the behind to hook up the rest.

Give her power!

In a bad Star Trek parody scene, we’re now going to “give her more power!” Now for some demented reason we haven’t fully switched over to the 24-pin main power cable yet. Some are still using only 20-pin power cables. So some dumb arse invented the “20+4″ pin power cable. Which sounds adaptable. And it is. But it’s also a bit of a pain to work with. You plug in the +4 cable, hopefully putting it into the right spot (at least I know where it goes, but not everyone may have my experience) and then plug in the old 20-pin standard cable with the clip to hold it in place. And hopefully that 20-pin cable also has little bobs on the end to hold down that +4 cable so it can’t come free. And then there’s the part that so many newbies forget, the new addition of a 12v 4-pin CPU cable. You really don’t want to forget that. If you do, your system probably won’t boot. Nothing bad should happen other than that, but getting it right the first time is always the best way to do things. Why this extra cable wasn’t made part of the main power cable is beyond me. But so now we have to basically deal with 20+4+4. Goofy to say the least. I say it’s time for a new standard. Keep it simple, stupid!

And wire we're at it...

And wire we’re at it, let’s hook up all of those extra wires and cables and doo-dads. Okay, so I’m screwing my air flow a bit by not using rounded IDE and floppy cables. You can see how the innovation of using Serial ATA (the SATA cable is the red one at the bottom) sure helps a computer’s air flow. No more bulky cables blocking things up in there if you can go all SATA. Me, I just don’t trust SATA optical drives yet, so I went with an IDE still. And while most people would wonder why bothered to install a floppy, all I can say is you never know when you’ll need it. Yes, USB sticks are much better. But better safe than sorry in my opinion. So that’s the mad mess of cables. Some of them are tied down a bit here and there, but until I transfer all of the data from the old PC’s hard drive (not installed yet) to this box, I’m not going to tie down every last cable. But trust me, I will. A clean box is a happy box.

Tada!  It's a computer!

Viola! Tada! It’s a computer! It was assembled by me. With completely legal and legit software (including MS Office, by request) for a smacking $550. Not bad. You’d be hard-pressed to get a complete match to that out of Dell and the likes. And unlike Dell, I didn’t use a ton of cut-rate corner-cutting parts that will break down. In fact after torture testing overnight in a tiny office with the door closed (meaning the ambient temperature in the room could heat up to baking in that time) the PC not only survived a SiSoftware Sandra burn in, but did so at an average CPU temp of 28 degrees Celsius. This is a system that was built well and will last the test of time.

And for all of you geeks out there who noticed, yes, that is a Star Trek movie on the TV in the background. Is there really anything better for a geek to build a new computer to? It was fate.

And now, for the hours and hours of installing software and running Windows Updates. And setting everything up. And validating. Et cetera.

And then? The hours and hours of copying data from the old hard drive to the new computer.

But then she’ll be good to go! Aw yeah!

Dualcore - Do You Get It? Do You NEED It?

A picture of the insides of a dualcore Opteron CPU.

They’re as common as chips today. Dualcore CPUs are everywhere you look. They’re almost the standard now, and quadcore (or higher) are the much ballyhooed upper end. But do you really know what a dualcore processor even is? More importantly, do you actually know what having one means? Here’s a little help for the common (and perhaps not so common) woman and man.

At its heart, a dualcore processor is simple. Take two computer processors. Squish them together. Give them one socket to plug in to so that seems like they’re one processor. Now you have a dualcore CPU. It’s literally two computer processors in one. How these two processors talk to each other (and everything else in your computer) varies widely. For the most part it makes little difference. Oh sure, geeks can argue the finer details of this until they’re blue in the face, but when it comes down to the performance that you and I see, the technical details matter very little. In high-use servers they matter. In desktop and laptop computers, they don’t.

Now, you might be thinking this is great. Two processors in one, that’s like double the processing power. So everything should run twice as fast. Well, sorry, but wrong.

Yes you have a theoretical doubling of performance. There is twice as much of everything there. But that double is still split in two. And more often than not, a single task cannot be split into two for both cores in your dualcore to work on simultaneously.

At the risk of getting into too much technical detail, I’ll break down why. There are two ways to write a computer program. The first is called single-threaded. (A thread is like a strand of code.) Single-threaded programs are easy to write. They were the first kind. All logic flows in a simple easy to understand manner. You calculate A. You perform A. You calculate B. You perform B. It’s all very straight forward. The behavior is very easy to understand and predict. And the only flaw to this method is that because the logic only runs through a single thread, only one core at a time can run this kind of program. In a dualcore CPU the other core will sit there and twiddle its thumbs.

The other way to write a computer program is called multi-threaded. The program is in effect broken down into smaller part-programs, called threads. These threads are then woven together by a lot of code to synchronize and control them. Because the program is broken down into parts this allows each core to grab at least one part of the program for itself, so no core sits idle. The gain is that in computers with multiple processors or a processor with multiple cores the program, as broken into threads, can run parts on each processor and/or core, effectively using a lot more of the resources available. The downside however is many fold. On a single core processor where there are no additional resources to be gained, the overhead of timing, control, communication, and synchronization of the threaded parts causes a loss in performance. Also all of this overhead creates many new places in the program for things to go wrong or even break, meaning a lot more bugs are likely to be in the program. But on top of that all, the job of the programmer to sort non-linearly through this multi-threaded code to find and fix bugs becomes exponentially more challenging than stepping through linear single-threaded code. So this all adds to a vast increase in development time and cost of a program, as well as greatly increasing the likelihood that it will be sold with unfixed flaws.

But that still isn’t all. On top of it all is the simple fact that not all computer programs lend themselves well to being broken into smaller pieces. Some programs do. Programs that repeatedly perform the same tasks over and over for example, can run several instances of those same tasks simultaneously in a multi-threaded program to fully utilize a dualcore processor. And programs that perform a vast multitude of very simple calculations that do not depend upon each other, such as the artificial intelligences that run opponents in a game, can also be split well into a multi-threaded program that will well use a dualcore CPU. However, many programs don’t perform tasks that can be broken up. One answer always depends on the previous, and so forth, so that the mathematics cannot be split up. While other programs (like word processors, email, web browsers, et cetera) simply don’t do much and are always just sitting there idle, waiting for user input. So they have nothing to gain from multi-threading.

And finally, one thing that often happens is that when you get a dualcore processor, each core actually runs slower than a processor of equal value with just one core. And since most programs are single-threaded and thus can only use one core at a time, they will run slower on that slower-clocked dualcore than if you had that faster-clocked single core processor.

So in light of all of this, what does having a dualcore CPU actually give you?

Well, for starters, switching between programs should be much smoother. For people who multi-task it will make a notable improvement in the snappiness and responsiveness of switching back and forth between programs. It also allows multiple programs to better run at the same time. Since today we have so many programs running in the background (anti-virus, firewall, chat and IMs, email, audio player, and so forth) a dualcore processor allows you to run what you want to run unhindered by all of those little things. And, of course, there are some programs like image editing software and some games that can greatly take advantage of both cores of a dualcore processor.

So the next time you go to buy a new computer or upgrade your computer processor, take a real hard look at what you do on your computer. Are the programs you run going to need a lot of processing power? Are the programs you run multi-threaded? Are you a multi-tasker that runs a lot of programs simultaneously? The answers to these questions will help you better choose the computer processor that you need.