-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(levm): Add BubbleSort benchmark (#1839)
**Motivation** Adding more benchmarks to have an idea of how we fare vs other implementations and find possible improvements. **Description** We add a new benchmark: - `BubbleSort`: Creates an array of n random elements, sorts it via bubble-sort and then checks the array is sorted. <!-- Link to issues: Resolves #111, Resolves #222 -->
- Loading branch information
1 parent
c2c3181
commit 0ad6473
Showing
5 changed files
with
46 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
crates/vm/levm/bench/revm_comparison/contracts/BubbleSort.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.17; | ||
|
||
contract BubbleSort { | ||
uint256[] public numbers; | ||
|
||
function Benchmark(uint256 amount) public returns (uint8 result) { | ||
// Fill array with random numbers | ||
for (uint256 i = 0; i < amount; i++) { | ||
numbers.push(uint256(keccak256(abi.encodePacked(block.timestamp, block.prevrandao, i))) % 100); | ||
} | ||
uint256 n = numbers.length; | ||
for (uint256 i = 0; i < n - 1; i++) { | ||
for (uint256 j = 0; j < n - i - 1; j++) { | ||
if (numbers[j] > numbers[j + 1]) { | ||
(numbers[j], numbers[j + 1]) = (numbers[j + 1], numbers[j]); | ||
} | ||
} | ||
} | ||
// Ensure the array is sorted | ||
for (uint256 i = 0; i < n - 1; i++) { | ||
require(numbers[i] <= numbers[i + 1]); | ||
} | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters