70 karma · joined Apr 4, 2011 (15y ago) · 25 submissions
comment 15y ago · link · parent
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.
comment 15y ago · link · parent
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).comment 15y ago · link · parent
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.
comment 15y ago · link · parent
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.
comment 15y ago · link · parent
You understood correctly, it's just how it gets phrased.
comment 15y ago · link · parent
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.
comment 15y ago · link · parent
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.
comment 15y ago · link · parent
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.
12.
Embeddable Bitcoin Miner for Websites(bitcoinplus.com ↗)
5 points · by dnadolny · 15y ago · 13 comments
comment 15y ago · link · parent
I vaguely remember hearing other stories where chips were made with secret backdoors in them, but I can't seem to find any.
comment 15y ago · link · parent
[1] http://forum.bitcoin.org/index.php?topic=8780.msg127782#msg1...
comment 15y ago · link · parent
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.
comment 15y ago · link · parent
I wonder, what's the math behind the electricity use of an idle CPU vs a CPU at 100%?
comment 15y ago · link · parent
If anyone's interested in that, leave a reply here, or email me at donny@bitcoinplus.com and I'll let you know when it's ready.
comment 15y ago · link · parent
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)
24.
Browser Bitcoin Miner(bitcoinplus.com ↗)
13 points · by dnadolny · 15y ago · 22 comments