aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-05-09 16:56:48 +0800
committerGitHub <noreply@github.com>2018-05-09 16:56:48 +0800
commitc79351efb05be08f3f1797c8cf6ff50988b74763 (patch)
tree0ee137fa5a96b7b7b05ac5702dc8a386980f8fd6 /test/libsolidity
parent58c63dcc9ce61b2742a10dc337cc5d0fd8739471 (diff)
parentbbae4fb0ef41361d24eadcc0a93cf02052493d10 (diff)
downloaddexon-solidity-c79351efb05be08f3f1797c8cf6ff50988b74763.tar
dexon-solidity-c79351efb05be08f3f1797c8cf6ff50988b74763.tar.gz
dexon-solidity-c79351efb05be08f3f1797c8cf6ff50988b74763.tar.bz2
dexon-solidity-c79351efb05be08f3f1797c8cf6ff50988b74763.tar.lz
dexon-solidity-c79351efb05be08f3f1797c8cf6ff50988b74763.tar.xz
dexon-solidity-c79351efb05be08f3f1797c8cf6ff50988b74763.tar.zst
dexon-solidity-c79351efb05be08f3f1797c8cf6ff50988b74763.zip
Merge pull request #4068 from ethereum/gasEstimatorPerformance
Gas estimator performance
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/GasMeter.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/libsolidity/GasMeter.cpp b/test/libsolidity/GasMeter.cpp
index 0d66456c..f16d9abe 100644
--- a/test/libsolidity/GasMeter.cpp
+++ b/test/libsolidity/GasMeter.cpp
@@ -307,6 +307,46 @@ BOOST_AUTO_TEST_CASE(regular_functions_exclude_fallback)
testCreationTimeGas(sourceCode);
testRunTimeGas("x()", vector<bytes>{encodeArgs()});
}
+
+BOOST_AUTO_TEST_CASE(complex_control_flow)
+{
+ // This crashed the gas estimator previously (or took a very long time).
+ // Now we do not follow branches if they start out with lower gas costs than the ones
+ // we previously considered. This of course reduces accuracy.
+ char const* sourceCode = R"(
+ contract log {
+ function ln(int128 x) constant returns (int128 result) {
+ int128 t = x / 256;
+ int128 y = 5545177;
+ x = t;
+ t = x * 16; if (t <= 1000000) { x = t; y = y - 2772588; }
+ t = x * 4; if (t <= 1000000) { x = t; y = y - 1386294; }
+ t = x * 2; if (t <= 1000000) { x = t; y = y - 693147; }
+ t = x + x / 2; if (t <= 1000000) { x = t; y = y - 405465; }
+ t = x + x / 4; if (t <= 1000000) { x = t; y = y - 223144; }
+ t = x + x / 8; if (t <= 1000000) { x = t; y = y - 117783; }
+ t = x + x / 16; if (t <= 1000000) { x = t; y = y - 60624; }
+ t = x + x / 32; if (t <= 1000000) { x = t; y = y - 30771; }
+ t = x + x / 64; if (t <= 1000000) { x = t; y = y - 15504; }
+ t = x + x / 128; if (t <= 1000000) { x = t; y = y - 7782; }
+ t = x + x / 256; if (t <= 1000000) { x = t; y = y - 3898; }
+ t = x + x / 512; if (t <= 1000000) { x = t; y = y - 1951; }
+ t = x + x / 1024; if (t <= 1000000) { x = t; y = y - 976; }
+ t = x + x / 2048; if (t <= 1000000) { x = t; y = y - 488; }
+ t = x + x / 4096; if (t <= 1000000) { x = t; y = y - 244; }
+ t = x + x / 8192; if (t <= 1000000) { x = t; y = y - 122; }
+ t = x + x / 16384; if (t <= 1000000) { x = t; y = y - 61; }
+ t = x + x / 32768; if (t <= 1000000) { x = t; y = y - 31; }
+ t = x + x / 65536; if (t <= 1000000) { y = y - 15; }
+ return y;
+ }
+ }
+ )";
+ testCreationTimeGas(sourceCode);
+ // max gas is used for small x
+ testRunTimeGas("ln(int128)", vector<bytes>{encodeArgs(0), encodeArgs(10), encodeArgs(105), encodeArgs(30000)});
+}
+
BOOST_AUTO_TEST_SUITE_END()
}