Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.io.BufferedReader;
- import java.io.ByteArrayInputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.nio.charset.StandardCharsets;
- import java.util.Random;
- import static java.lang.System.currentTimeMillis;
- public class Test {
- public static void main(String[] args) throws IOException {
- Random random = new Random();
- for (int attempt = 0; attempt < 10; attempt++) {
- byte[] array = new byte[2_000_000_000];
- for (int i = 0; i < array.length; i++) {
- if (random.nextInt(64) == 0) {
- array[i] = 13;
- } else {
- array[i] = (byte) (32 + random.nextInt(127 - 32));
- }
- }
- int checksum = 0;
- long startTime = currentTimeMillis();
- for (int i = 0; i < array.length; i++) {
- checksum ^= array[i];
- }
- System.out.println(currentTimeMillis() - startTime);
- startTime = currentTimeMillis();
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(array);
- InputStreamReader inputStreamReader = new InputStreamReader(byteArrayInputStream, StandardCharsets.UTF_8);
- BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
- String line;
- while ((line = bufferedReader.readLine()) != null) {
- var lineLength = line.length();
- for (int i = 0; i < lineLength; i++) {
- checksum ^= line.charAt(i);
- }
- checksum ^= 13;
- }
- System.out.println(currentTimeMillis() - startTime);
- System.out.println(checksum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment