[C] swapping vars

Feel like posting Off Topic? Do it here.

Moderator: MaxCoderz Staff

User avatar
crzyrbl
Calc Wizard
Posts: 518
Joined: Wed 06 Jul, 2005 4:56 pm
Location: 3rd rock....

Post by crzyrbl »

I agree that readibility is important, but I don't really bother going through time.h or what have you, so I would rather it be insanely optimized rather than even somewhat readible. Then again, I've only really used high-level langauges like C++ and I don't know how often asm is used in the industry today. Still, in the case of Wiki's definition, I think that it should be in its most readible form, which it currently is. I assume King's optimization is based off of it somehow anyways. Thats my two cents.
(\__/)
(='.'=)This is Bunny. Copy and paste bunny into your
(")_(")signature to help him gain world domination.

Image
coelurus
Calc Wizard
Posts: 585
Joined: Sun 19 Dec, 2004 9:02 pm
Location: Sweden
Contact:

Post by coelurus »

I suspect at most one or two people find this thread constructive now as it came to a dead end on the first page. Shelling out advice on how to go from here is the most constructive thing I can think of and I could only think of one thing to say... Sorry if my advice insulted you, but your lack of understanding what has been said in this thread can be insulting too ;)

I also fail to see why not a single person has minded the little hints in every one of my posts as to why this thread is pointless.

Alright, this is definitely my last post in here :)
User avatar
hop
Extreme Poster
Posts: 378
Joined: Sat 09 Dec, 2006 3:42 pm

Post by hop »

It takes two people for one to stay in misunderstanding of the other's arguments.
CoBB
MCF Legend
Posts: 1601
Joined: Mon 20 Dec, 2004 8:45 am
Location: Budapest, Absurdistan
Contact:

Post by CoBB »

crzyrbl wrote:I agree that readibility is important, but I don't really bother going through time.h or what have you, so I would rather it be insanely optimized rather than even somewhat readible.
But you will be going through at least your own old code quite often. You can’t expect yourself to remember how it works after a few weeks.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

But you will be going through at least your own old code quite often. You can’t expect yourself to remember how it works after a few weeks.
comments? :P
I also fail to see why not a single person has minded the little hints in every one of my posts as to why this thread is pointless.
well if you look at it like that, every discussion is pointless because no one is going to change his or her opinion anyway, except kids whom you can still tell anything and they'll believe it.
Sorry if my advice insulted you, but your lack of understanding what has been said in this thread can be insulting too
sure, but I understand it alright, I don't have to agree with it. I certainly see that some/most ppl aren't going to bother optimizing at a low lvl, but that's their problem, imo they should take the time to do that - if available.
User avatar
tr1p1ea
Maxcoderz Staff
Posts: 4141
Joined: Thu 16 Dec, 2004 10:06 pm
Location: I cant seem to get out of this cryogenic chamber!
Contact:

Post by tr1p1ea »

You think it would be a better idea to try and optimise the whole quicksort routine, rather than just dwell on the swap function? That would actually be a good exercise, and could prove very useful imo.
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

well.. isn't quicksort generally the fastest algorithm anyway? meaning it's already high-level optimized - which leaves low lvl optimizing.
coelurus
Calc Wizard
Posts: 585
Joined: Sun 19 Dec, 2004 9:02 pm
Location: Sweden
Contact:

Post by coelurus »

Buy that can... You're saying very devious things. To be more specific, quicksort is not generally the fastest algorithm, it's actually considered unreliable and there are very good reasons for that. Even my friends who had no idea what the three xors did know why quicksort is bad (and they've built their own hardware and protocols for wireless communication and a wiimote workalike).

Crap, I keep forgetting myself! :)
User avatar
Jim e
Calc King
Posts: 2457
Joined: Sun 26 Dec, 2004 5:27 am
Location: SXIOPO = Infinite lives for both players
Contact:

Post by Jim e »

I knew you'd keep posting...

King Harold wrote:well.. isn't quicksort generally the fastest algorithm anyway? meaning it's already high-level optimized - which leaves low lvl optimizing.
No not quicksort...and even if you say there is a fastest that still doesn't mean best. You need to use whats appropriate for what your doing.

The low level optimizing you want to do is changing the code so it does the exact same thing but in a different better way. Problem is Compilers WILL disagree with you, so unless you are programming in assembly its very unlikely that you can improve low level. Especially with all these new fangled high level languages.

High level optimization, which everyone is saying is more important, is changing the actual workings of the code, it no longer does the same thing, but will achieve you goal in a better way.

I mean you could low level optimize the hell out of a sort routine but that doesn't really improve it to much... Go take a look at the programming contest MaxCoderz had, 15 byte routines all utterly worthless.


High level also has the benefit of being mostly portable to multiple machines, where as low level requires knowledge of the machine and what does best on it.
Image
User avatar
tr1p1ea
Maxcoderz Staff
Posts: 4141
Joined: Thu 16 Dec, 2004 10:06 pm
Location: I cant seem to get out of this cryogenic chamber!
Contact:

Post by tr1p1ea »

King Harold wrote:well.. isn't quicksort generally the fastest algorithm anyway? meaning it's already high-level optimized - which leaves low lvl optimizing.
... Isnt that what i said, i didnt say optimise the algorithm, i meant the routine. Perhaps there is a better implementation. But like already mentioned, quicksort isnt suited to all data nor can you use it on every machine effectively.

This thread is supposed to be about optimisation ideas, yet the only thing present is a basic demonstration of how xor works, which [typically] isnt even an optimisation.

Anyone have any real optimisations or quick C routines?
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image
User avatar
crzyrbl
Calc Wizard
Posts: 518
Joined: Wed 06 Jul, 2005 4:56 pm
Location: 3rd rock....

Post by crzyrbl »

CoBB wrote:
crzyrbl wrote:I agree that readibility is important, but I don't really bother going through time.h or what have you, so I would rather it be insanely optimized rather than even somewhat readible.
But you will be going through at least your own old code quite often. You can’t expect yourself to remember how it works after a few weeks.
well if it's my own code, of course I'm going to make it readible or add comments. I did not intend to imply otherwise.
(\__/)
(='.'=)This is Bunny. Copy and paste bunny into your
(")_(")signature to help him gain world domination.

Image
coelurus
Calc Wizard
Posts: 585
Joined: Sun 19 Dec, 2004 9:02 pm
Location: Sweden
Contact:

Post by coelurus »

This thread is supposed to be about "Swapping vars" according to the title.
CoBB
MCF Legend
Posts: 1601
Joined: Mon 20 Dec, 2004 8:45 am
Location: Budapest, Absurdistan
Contact:

Post by CoBB »

coelurus wrote:This thread is supposed to be about "Swapping vars" according to the title.
But you don't really want that, do you? :P
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

Now now folks, the idea was to come up with something that no one would agree with so as to start a discussion. That part worked really well as you can see.

I know quicksort is not the best for all data sets, but it's generally the fastest isn't it? Fastest doesn't necessarily mean 'best' but it comes quite close to it, atleast if you don't want to spend a considerable percentage of the programs running time to sorting - it probably has better things to do of which the sorting is only a small part. Ofcourse, quicksort isn't the best when - forexample - the array is already mostly sorted - how about insertion sort? heap sort? -, or when the array is extremely short (like 2 elements long - in which case you only need to test which is bigger and decide whether or not to swap them).
This thread is supposed to be about "Swapping vars" according to the title.
that's to trick you into posting ;)

now..
Anyone have any real optimisations or quick C routines?
coelurus
Calc Wizard
Posts: 585
Joined: Sun 19 Dec, 2004 9:02 pm
Location: Sweden
Contact:

Post by coelurus »

I never saw the point with bringing up discussions with no conclusions, so far I haven't learnt a thing from this thread :)

Quicksort could be considered as "generally" the fastest, but you used that as an argument to condone low level optimization. When you do specific low level optimizing, then you don't have a "general" application anymore and thus a high level optimization will yield far better results.

If we're gonna get into optimized routines, then a change of the thread title might be in order?
Locked