Hold a popular vote and then select from among the candidates randomly, weighted by their popular vote percentages.
In a two candidate race that both get 50% of the vote, the electorate has essentially said "We don't clearly know who's better." So flip a coin and go with that one. In a three way race where the 'spoiler' candidate receives 20% of the vote, select him as the winner with a 20% probability.
Pros: * The majority doesn't completely drown out the rest. * Less susceptible to small counting errors. (i.e. the OP).
Cons: No chance of this being perceived fair. The conspiracy theorists are going to go apeshit the first time a 20% winner gets elected.
Revision: Perhaps use a non-uniform distribution to push the percentages further towards the extreme--e.g. a winner of 80% of the electorate should probably be chosen 95% of the time.
The human rebels break into an air force base that has been abandoned for 1000 years, learn to fly harrier jets (that still work fine) by training on a simulator for a few days (electricity?) and then hover inside the shells of the old skyscrapers. Now I'm no Harrier pilot, but I would bet that no Harrier pilot would try to pull off a stunt like that.
To top it off they then use the jets to dogfight the alien fighter planes, defeating the aliens that had previously wiped out all of Earth's military might in 15 minutes.
I skipped school to see that movie, and wished I hadn't.
From what I recall reading a while back, calling garbage collection is explicitly discouraged. Even if this is just a hint, the more often it is called the more likely the garbage collector is to run. Since running the garbage collector IS very expensive you want to reduce the frequency with which you need to call it, not increase the frequency.
If you are really conerned that the test will end before the GC has been called then make the test longer. These two systems are designed to be used differently, trying to cast one as another is going to just lead to bad results. Besides, from what I've read and my experience working in C#, GC happens fairly often, the test probably doesn't even need to be that long in order to hit GC at least once.
We have a little windows forms app written in C# that plays around with images. At startup it recurses through a large directory structure and builds several ArrayLists, the largest of about 3000 objects.
During this short time, about 0.61s of processor time, it performs 5 gen0, 3 gen1, and 3 gen2 garbage collections. There is just short of 4 megs in all of the heaps at the end.
Now these are rough numbers about one (maybe a bit poorly written) little app, but I was hoping to give an idea that GC is occuring a lot even without you forcing it to, and that it is not necessarily the albatross that it is sometimes made out to be.
As for Garbage Collection being good for some workloads but not for others, I echo everyone else in agreeing, make the benchmark an actual workload, not a contrived function. I think GC is a great idea that a good implementation of which could lead to increased performance in a lot of situations. However, good benchmarks showing how the current generation of garbage collectors are performing are not easy to perform, and so are few and far between.
I agree with the overall point that you are trying to make. However, your main argument against this snippet of code seems to boil down to you don't know how the function is supposed to behave. Shouldn't that be commented on the function itself and not the function call?
Hold a popular vote and then select from among the candidates randomly, weighted by their popular vote percentages.
In a two candidate race that both get 50% of the vote, the electorate has essentially said "We don't clearly know who's better." So flip a coin and go with that one. In a three way race where the 'spoiler' candidate receives 20% of the vote, select him as the winner with a 20% probability.
Pros:
* The majority doesn't completely drown out the rest.
* Less susceptible to small counting errors. (i.e. the OP).
Cons:
No chance of this being perceived fair. The conspiracy theorists are going to go apeshit the first time a 20% winner gets elected.
Revision:
Perhaps use a non-uniform distribution to push the percentages further towards the extreme--e.g. a winner of 80% of the electorate should probably be chosen 95% of the time.
The Burning Edge, one of Jesse Ruderman's pages, is a pretty good resource to get a summary of what is the latest and greatest in Firefox development.
He also has one that summurizes the differences between releases: http://www.squarefree.com/burningedge/releases/. It looks like he hasn't updated it for 2.0 yet though.
Second!
I have my reservations about Python, largely based on its scoping rules, but this was fun series of programming riddles.
I have never used any of those keys until reading the above post. As soon as I tested it though, I found that they work just fine.
However I have already installed the drivers for this keyboard to get the media (volume play pause etc) keys to work a while back.
Are you saying that those keys work in IE even without having installing the Microsoft keyboard stuff?
You missed my favorite part: the fighter jets.
The human rebels break into an air force base that has been abandoned for 1000 years, learn to fly harrier jets (that still work fine) by training on a simulator for a few days (electricity?) and then hover inside the shells of the old skyscrapers. Now I'm no Harrier pilot, but I would bet that no Harrier pilot would try to pull off a stunt like that.
To top it off they then use the jets to dogfight the alien fighter planes, defeating the aliens that had previously wiped out all of Earth's military might in 15 minutes.
I skipped school to see that movie, and wished I hadn't.
From what I recall reading a while back, calling garbage collection is explicitly discouraged. Even if this is just a hint, the more often it is called the more likely the garbage collector is to run. Since running the garbage collector IS very expensive you want to reduce the frequency with which you need to call it, not increase the frequency.
If you are really conerned that the test will end before the GC has been called then make the test longer. These two systems are designed to be used differently, trying to cast one as another is going to just lead to bad results. Besides, from what I've read and my experience working in C#, GC happens fairly often, the test probably doesn't even need to be that long in order to hit GC at least once.
We have a little windows forms app written in C# that plays around with images. At startup it recurses through a large directory structure and builds several ArrayLists, the largest of about 3000 objects.
During this short time, about 0.61s of processor time, it performs 5 gen0, 3 gen1, and 3 gen2 garbage collections. There is just short of 4 megs in all of the heaps at the end.
Now these are rough numbers about one (maybe a bit poorly written) little app, but I was hoping to give an idea that GC is occuring a lot even without you forcing it to, and that it is not necessarily the albatross that it is sometimes made out to be.
As for Garbage Collection being good for some workloads but not for others, I echo everyone else in agreeing, make the benchmark an actual workload, not a contrived function. I think GC is a great idea that a good implementation of which could lead to increased performance in a lot of situations. However, good benchmarks showing how the current generation of garbage collectors are performing are not easy to perform, and so are few and far between.
Great one!
According to some of the spam I get it can never be big enough.
I agree with the overall point that you are trying to make. However, your main argument against this snippet of code seems to boil down to you don't know how the function is supposed to behave. Shouldn't that be commented on the function itself and not the function call?