Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×

Comment Re:It depends (Score 1) 486

Even if you wrote this in C in the style in which they did it the program would be slow. Since there's no way to "extend" a C string, it would require determining the length of the current string (which involves scanning the string for a null byte), malloc'ing a new buffer with one more byte,

There is. It is called realloc. If you are unlucky, it will just divide the number of times the system actually performs by 16 or whatever the malloc implementation uses as an alignment, but once the allocation gets big enough you get a pages directly from the system, and it just maps in more pages on the end.

malloc isn't the problem, though. My point was that if you write it in the style of the code in the paper (don't keep track of the string length between character appends) then it'll still have to scan the string a million times. If you know ahead of time that you're going to append exactly one million characters to the string then you need but one malloc, right? I can make this program extremely fast in that manner but that's not what they're doing.

The Almighty Buck

Russian Official Proposes Road That Could Connect London To NYC 226

An anonymous reader writes There's great news coming out of Russia for epic road trip lovers. Russian Railways president Vladimir Yakunin has proposed building a highway that would reach from London to Alaska via Russia, a 13,000-mile stretch of road. "This is an inter-state, inter-civilization, project," the Siberian Times quoted Yakunin. "The project should be turned into a world 'future zone,' and it must be based on leading, not catching, technologies."

Comment Re:It depends (Score 2) 486

Well, yeah, but that's not going to work consistently. Worst case is if the string is on the stack you'll smash the stack and likely have a memory access error. If it's on the heap you'll likely get the error quicker.

I wouldn't even think of writing a program in the manner in which their sample was written, but if I was trying to solve their basic "problem" there are better ways to go about it.

Comment Re:It depends (Score 3, Insightful) 486

The real story here, is that if you don't know how to write code properly, then string concatenation can be really slow.

Was their paper peer reviewed?

I just reviewed it, but frankly, they're not my peers.

They actually understand the problem and state it near the end of the paper. The issue is pretty simple and when I read the /. summary I knew what the problem was. They're appending single bytes to a string. In both chosen languages - Java and Python - strings are immutable so the "concatenation" is way the hell more complex than simply sticking a byte in a memory location. What it involves is creating a new string object to hold both strings together. So, there's the overhead of object creation, memory copying, etc. Yes, by the time you're done it's a lot of extra work for the CPU.

I'm going to state this as nicely as I can: what they proved is that a complete moron can write code so stupidly that a modern CPU and RAM access can be slowed down to the extent that even disk access is faster. That's it.

Even if you wrote this in C in the style in which they did it the program would be slow. Since there's no way to "extend" a C string, it would require determining the length of the current string (which involves scanning the string for a null byte), malloc'ing a new buffer with one more byte, copying the old string and then adding the new character and new null byte. Scanning and copying are both going to require an operation for each byte (yeah, it could be optimized to take advantage of the computer's word length) on each iteration, with that byte count growing by "1" each time.

The sum of all integers up to N is N(N+1)/2. If N is 1,000,000 the sum is 500,000,500,000. So, counting bytes (looking for null) requires half a trillion operations and copying bytes requires another half trillion operations. Note that "operations" is multiple machine instructions for purposes of this discussion.

Yeah, modern computers are fast, but when you start throwing around a trillion operations it's going to take some time.

Writing to disk will be faster for a number of reasons, mainly because the OS is going to buffer the writes (and know the length of the buffer) and handle it much much better. It's not doing a disk operation every time they do a write. If they were to flush to disk every time they would still be waiting for it to finish.

There are a few notes, here. First, in Java and Python the string object likely holds a "length" value along with the actual character buffer. That would make it faster and not require all the operations the badly written C code that I describe above would require. But the overhead of objects, JVM, interpreter, etc. gets thrown into the mix. Second, if I were doing something like this in C I could keep the string length as part of a struct and at least make it that much faster. The point is that a good programmer wouldn't write code in this manner.

Anyway, this "paper" proves nothing except that really bad code will always suck. One would have to be an idiot to write anything close to what they've done here in a real-life scenario. I know because I've cleaned up other people's code that's on the level of this junk...

Programming

No, It's Not Always Quicker To Do Things In Memory 486

itwbennett writes: It's a commonly held belief among software developers that avoiding disk access in favor of doing as much work as possible in-memory will results in shorter runtimes. To test this assumption, researchers from the University of Calgary and the University of British Columbia compared the efficiency of alternative ways to create a 1MB string and write it to disk. The results consistently found that doing most of the work in-memory to minimize disk access was significantly slower than just writing out to disk repeatedly (PDF).

Comment Re:Costa Rica (Score 1) 317

"Things happen when they happen, and no one is in a hurry to get anything done or to go anywhere"
I think that's symptomatic of many tropical places with good cheap food. There's little danger of starving or freezing to death so few are eager to join the rat race.

About 25 years ago, a few of my uncles got quite the dose of culture shock when they were trying to run a midscale restaurant and B&B in Barbados.
Getting fresh seafood delivered 3 days in a row would drive a hostage negotiator to suicide.

Comment Re:Elon Musk vs Richard Branson (Score 2) 105

"He makes cars for the upper class"

Oh, for f*cks sake, his stated goal, as published on the Tesla Motors website in Aug 2006 is

"Almost any new technology initially has high unit cost before it can be optimized and this is no less true for electric cars. The strategy of Tesla is to enter at the high end of the market, where customers are prepared to pay a premium, and then drive down market as fast as possible to higher unit volume and lower prices with each successive model."

He's taking longer than he thought and it'll take one or 2 more models to get to mass market affordable cars but he's making a lot of moves to make sure that happens, eg battery Gigafactory.

Comment Re:Elon Musk vs Richard Branson (Score 1) 105

Heh, no. It would be ADD if his companies never delivered on anything and, of course, there are a lot of smart, hardworking people behind him - one can hardly disregard the talent of JB Straubel.

But he is the front man and the one'll get the arrows in the back if his ventures fail.
In just the past 5 years, his resume is damned impressive with what has been accomplished at SpaceX, Tesla, Solar City, Silevo so for now, he's earned the badge of a highly successful multi-tasker, the only blemish is that his companies are not yet profitable.

Comment Re:Elon Musk vs Richard Branson (Score 1) 105

I realize I forgot to mention Virgin Galactic which Branson founded 2 yrs after Musk started SpaceX.
They've been promising a maiden flight since 2009 but it seems that was more marketing than reality and they're not quite ready.
With the midair explosion of SpaceShipTwo last October, it remains to be seen what they do next.

Comment Re:Elon Musk vs Richard Branson (Score 4, Insightful) 105

Bitch, please, that's not even a contest.
Branson started off with a magazine & record stores before launching an airline; Elon sold a space shooter video game as a 12yr old and was studying physics & material science at Stanford, is invested in SOLAR energy, considers running SpaceX to be his primary job & still found time to put his thoughts on the Hyperloop on paper while showcasing the launch of the most kickass electric sedan ever made.

http://www.theatlantic.com/tec...

It may be that there's someone more deserving of the title than Musk but it ain't Branson, not now, not ever.

Slashdot Top Deals

It's not an optical illusion, it just looks like one. -- Phil White

Working...