MCPcopy Create free account
hub / github.com/argotorg/solidity / formatGasDiff

Function formatGasDiff

test/libsolidity/util/TestFunctionCall.cpp:341–357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

339{
340
341std::string formatGasDiff(std::optional<u256> const& _gasUsed, std::optional<u256> const& _reference)
342{
343 if (!_reference.has_value() || !_gasUsed.has_value() || _gasUsed == _reference)
344 return "";
345
346 solUnimplementedAssert(*_gasUsed < u256(1) << 255);
347 solUnimplementedAssert(*_reference < u256(1) << 255);
348 s256 difference = static_cast<s256>(*_gasUsed) - static_cast<s256>(*_reference);
349
350 if (*_reference == 0)
351 return fmt::format("{}", difference.str());
352
353 int percent = static_cast<int>(
354 100.0 * (static_cast<double>(difference) / static_cast<double>(*_reference))
355 );
356 return fmt::format("{} ({:+}%)", difference.str(), percent);
357}
358
359// TODO: Convert this into a generic helper for getting optional form a map
360std::optional<u256> gasOrNullopt(std::map<std::string, u256> const& _map, std::string const& _key)

Callers 1

formatGasExpectationsMethod · 0.85

Calls 1

strMethod · 0.80

Tested by

no test coverage detected