Created
May 30, 2018 08:39
-
-
Save santtu/c47f667812051b20721e3293babd061e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import org.web3j.protocol.Web3j; | |
| import org.web3j.protocol.core.DefaultBlockParameterNumber; | |
| import org.web3j.protocol.ipc.UnixIpcService; | |
| import java.io.IOException; | |
| import java.time.Duration; | |
| import java.time.Instant; | |
| public class Web3jSpeedTest { | |
| public static void main(String[] args) throws IOException { | |
| if (args.length != 3) { | |
| System.err.println("Give three arguments: IPC-PATH START-BLOCK END-BLOCK"); | |
| return; | |
| } | |
| String path = args[0]; | |
| Long start = Long.parseLong(args[1]); | |
| Long end = Long.parseLong(args[2]); | |
| UnixIpcService service = new UnixIpcService(path); | |
| Web3j web3j = Web3j.build(service); | |
| Instant started = Instant.now(); | |
| int n = 0; | |
| for (Long block = start; block < end; block++) { | |
| System.out.print("" + block + " "); | |
| System.out.flush(); | |
| web3j.ethGetBlockByNumber(new DefaultBlockParameterNumber(block), true).send(); | |
| n++; | |
| } | |
| System.out.println(" done"); | |
| Instant finished = Instant.now(); | |
| double elapsed = Duration.between(started, finished).toMillis() / 1000.0; | |
| System.out.println("" + n + " blocks in " + elapsed + " seconds"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment