Incredibly slow function, for the fun.

TheWolfTheWolf Member Posts: 6
Hi everybody, I am new at Solidity, and so far I love it.
I will be participating to this forums, since I am doing an ICO soon and I am reading it.
Here is a fun thing. This small function it taking a LOT of time to compile (20s here, while the SNT contract is taking 5 seconds only!)

Maybe some guru can explain why this is taking so much time, there is no loop.
Also the magic of this function is to make run out of gas any contract.

function last(uint x) returns (uint) { uint last=x/1000000000000000000; if (last<=0) last=x/100000000000000000; if (last<=0) last=x/10000000000000000; if (last<=0) last=x/1000000000000000; if (last<=0) last=x/10000000000000; if (last<=0) last=x/1000000000000; if (last<=0) last=x/100000000000; if (last<=0) last=x/10000000000; if (last<=0) last=x/1000000000; if (last<=0) last=x/100000000; if (last<=0) last=x/10000000; if (last<=0) last=x/1000000; if (last<=0) last=x/100000; if (last<=0) last=x/10000; if (last<=0) last=x/100; if (last<=0) last=x/10; if (last<=0) last=x/1; return last; }

Have fun!

Comments

  • MatthewCampbellMatthewCampbell Member Posts: 4
    I tried to compile it and it only takes 5 seconds https://ethfiddle.com/3vE0fO8mOU not sure why you care about the compile time? Only thing that really matters is the gas. This function is just really unoptimized and uses a ton of extra work, it is doing a division, a variable assign and a branching statement, up to 22 times, so thats like equal to 150 lines of code. Its not clear for your post what your goal is here?
Sign In or Register to comment.