dnadolny
That was my first thought as well, but I double checked and the ordinal() method is final, so you're guaranteed not to get anything other than continuous values for your enums.
> in C compiled to x86 assembly language, a switch statement on (mostly-)contiguous values can be converted into a jump table
Ah, this is probably the intention. The JVM can probably optimize the switch. I just checked it, and when there are multiple switch statements in a class only using a few values in an enum, it tries to make them all sequential in the switch, that's why it uses the array. I guess it's just a mistake (or lazy coding) that it always makes the array size TheEnum.values().length rather than how many it's actually going to use.
I checked what happens when you use an enum, and it generates some funky code. It creates an anonymous inner class with a static initializer for an array of ints. It uses the ordinal value to assign a sequential number starting with one. Then the switch statement is on intArray[theEnum.ordinal()], and the case statements start with 1. Here's the code:
class Test2{
public static void main(String[] args) {
MyEnum en = MyEnum.ONE;
switch (en) {
case ONE:
System.out.println("one"); break;
case TWO:
System.out.println("two"); break;
default:
System.out.println("default");
}
}
}
enum MyEnum {
ONE, TWO, THREE;
}
Decompiled (after being compiled with jdk1.7.0): public static void main(String args[])
{
MyEnum myenum = MyEnum.ONE;
static class _cls1
{
static final int $SwitchMap$MyEnum[];
static
{
$SwitchMap$MyEnum = new int[MyEnum.values().length];
try
{
$SwitchMap$MyEnum[MyEnum.ONE.ordinal()] = 1;
}
catch(NoSuchFieldError nosuchfielderror) { }
try
{
$SwitchMap$MyEnum[MyEnum.TWO.ordinal()] = 2;
}
catch(NoSuchFieldError nosuchfielderror1) { }
}
}
switch(_cls1.$SwitchMap$MyEnum[myenum.ordinal()])
{
case 1: // '\001'
System.out.println("one");
break;
case 2: // '\002'
System.out.println("two");
break;
default:
System.out.println("default");
break;
}
}
I wonder why it doesn't just switch on the ordinal directly. It's also worth noting that it has to make an array for MyEnum.values().length. This means if you have an enum with a lot of values, you're wasting a lot of memory (especially since it creates this array every class you use a switch in).
I tried with an enum with 40 values, and it didn't switch to a map. Maybe there's some higher threshold where it would switch to a map instead (but again, I don't understand why it wouldn't switch on ordinal() directly).I just tried it out, it didn't get added to 7.
> String-in-switch (NOTE: check on performance implications of this for tight loops)
I haven't checked the performance, but I tried decompiling a String switch statement:
String test = "asdf";
switch (test) {
case "sss":
System.out.println("sss");
break;
case "asdf":
System.out.println("asdf");
break;
}
That decompiles to: switch(test.hashCode()) {
case 114195:
if(test.equals("sss"))
byte0 = 0;
break;
case 3003444:
if(test.equals("asdf"))
byte0 = 1;
break;
}
switch(byte0) {
case 0: // '\0'
System.out.println("sss");
break;
case 1: // '\001'
System.out.println("asdf");
break;
}
So it's one switch on the String's hashcode, with calls to equals to verify that the string is a match (and an if/else if/else block if you have multiple strings in the switch that have the same hashcode), assigning the result to a temp variable, and then a switch on a temp variable to execute your code.It looks like it would be fairly quick.
A recruiter could offer a lot of value, the problem is that it's difficult to show that you're a useful recruiter. This is an econ problem[1], where you have people offering something valuable and people offering something not very valuable and you can't tell the difference. What's needed is a way of signaling that they're going to be a good recruiter.
You understood correctly, it's just how it gets phrased.
I didn't think of marketing it to internet cafes/kiosks though.
As for the resource overhead of the JVM, it's infeasible to have a bitcoin miner that uses javascript - that was how I did it initially, as a proof of concept, but it was so slow I abandoned it.
Was it lagging when you were scrolling down? I try to play nice with the CPU and run it at low priority, so it shouldn't interfere. What OS/browser/java version combo has trouble?
It's around 30-40% slower than one of the optimized C CPU miners, and of course it's a a lot slower than a GPU miner, but it mines at a reasonable rate (and it starts up quickly)
As for effective monetization, this is something you can run in addition to regular ads if you wanted, since it doesn't take up any screen space.
I like the captcha idea, I've actually been planning something like that. I've got some changes I need to make to my infrastructure before I can do that, but I'm hoping to do it (or let other people do it with the API I'm going to offer).
Thanks for the advice about making the user feel appreciated, I think that's quite important.
The way I see it, websites with advertisements use your mind (by grabbing your attention). This only uses your computer. Which would you rather have a website try to take over?
I vaguely remember hearing other stories where chips were made with secret backdoors in them, but I can't seem to find any.
Would it change your mind if you were given a portion of the bitcoins generated while you were on a site that was doing this?
Which would you rather: a website use your mind by taking your attention to an advertisement, or a website using your CPU?
[1] http://forum.bitcoin.org/index.php?topic=8780.msg127782#msg1...
I tried out GPU mining but my computer was unusable while it was running.
I've been thinking this over for a while. Right now, the general consensus is that the price of bitcoin will end up being related to the cost of electricity for computing, and in the long run transaction fees will have to go up or down to make that happen.
I think this will change.
When you have negative externalities like this, where people don't pay for electricity (they're renting, or in a condo/apartment building that has electricity included) or even free CPU power, as in an office, then the economics change. The price of bitcoin won't be tied to the price of electricity/CPU power, it will be tied to the cost of running a website like mine that lets people take advantage of free CPU power.
I wonder, what's the math behind the electricity use of an idle CPU vs a CPU at 100%?
If anyone's interested in that, leave a reply here, or email me at [email protected] and I'll let you know when it's ready.
Right now it doesn't use the GPU but I've got plans to do it too (it might be able to work with the new OpenCL stuff that's going on)
I'd love to get some feedback on it.
Once the page loads, hit "Start generating" and it should start mining bitcoin.
Browser Bitcoin Miner
Having a solid network of friends and contacts does have quantifiable effects.