Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
neodix42 committed Sep 30, 2024
1 parent e4d8758 commit ddceb2f
Show file tree
Hide file tree
Showing 5 changed files with 733 additions and 748 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,132 +14,131 @@
@RunWith(JUnit4.class)
public class TestBitStringPerformance {

private static final int SIZE = 1_000_000;
private static final int SIZE = 1_000_000;

@Test
public void testWriteBitStringPerformance() {
BitString bitString = new BitString(SIZE);
long startTime = System.nanoTime();
@Test
public void testWriteBitStringPerformance() {
BitString bitString = new BitString(SIZE);
long startTime = System.nanoTime();

for (int i = 0; i < SIZE; i++) {
bitString.writeBit(i % 2 == 0);
}

long endTime = System.nanoTime();
long duration = endTime - startTime;
System.out.println("Write BitString performance: " + duration / 1_000_000 + " ms");

assertTrue("Test should complete in less than 300 ms", duration < 300_000_000);
for (int i = 0; i < SIZE; i++) {
bitString.writeBit(i % 2 == 0);
}

@Test
public void testReadBitStringPerformance() {
BitString bitString = new BitString(SIZE);
for (int i = 0; i < SIZE; i++) {
bitString.writeBit(i % 2 == 0);
}
long endTime = System.nanoTime();
long duration = endTime - startTime;
System.out.println("Write BitString performance: " + duration / 1_000_000 + " ms");

long startTime = System.nanoTime();
assertTrue("Test should complete in less than 300 ms", duration < 300_000_000);
}

for (int i = 0; i < SIZE; i++) {
bitString.readBit();
}
@Test
public void testReadBitStringPerformance() {
BitString bitString = new BitString(SIZE);
for (int i = 0; i < SIZE; i++) {
bitString.writeBit(i % 2 == 0);
}

long endTime = System.nanoTime();
long duration = endTime - startTime;
System.out.println("Read BitString performance: " + duration / 1_000_000 + " ms");
long startTime = System.nanoTime();

assertTrue("Test should complete in less than 300 ms", duration < 300_000_000);
for (int i = 0; i < SIZE; i++) {
bitString.readBit();
}

@Test
public void testWriteUintPerformance() {
BitString bitString = new BitString(SIZE);
long startTime = System.nanoTime();
long endTime = System.nanoTime();
long duration = endTime - startTime;
System.out.println("Read BitString performance: " + duration / 1_000_000 + " ms");

for (int i = 0; i < SIZE; i++) {
bitString.writeUint(i, 32);
}
assertTrue("Test should complete in less than 300 ms", duration < 300_000_000);
}

long endTime = System.nanoTime();
long duration = endTime - startTime;
System.out.println("Write Uint performance: " + duration / 1_000_000 + " ms");
@Test
public void testWriteUintPerformance() {
BitString bitString = new BitString(SIZE);
long startTime = System.nanoTime();

assertTrue("Test should complete in less than 300 ms", duration < 300_000_000);
for (int i = 0; i < SIZE; i++) {
bitString.writeUint(i, 32);
}

@Test
public void testReadUintPerformance() {
BitString bitString = new BitString(SIZE);
for (int i = 0; i < SIZE; i++) {
bitString.writeUint(i, 64);
}
long endTime = System.nanoTime();
long duration = endTime - startTime;
System.out.println("Write Uint performance: " + duration / 1_000_000 + " ms");

long startTime = System.nanoTime();
assertTrue("Test should complete in less than 400 ms", duration < 400_000_000);
}

for (int i = 0; i < SIZE; i++) {
bitString.readUint(64);
}
@Test
public void testReadUintPerformance() {
BitString bitString = new BitString(SIZE);
for (int i = 0; i < SIZE; i++) {
bitString.writeUint(i, 64);
}

long endTime = System.nanoTime();
long duration = endTime - startTime;
System.out.println("Read Uint performance: " + duration / 1_000_000 + " ms");
long startTime = System.nanoTime();

assertTrue("Test should complete in less than 300 ms", duration < 300_000_000);
for (int i = 0; i < SIZE; i++) {
bitString.readUint(64);
}

@Test
public void testWriteBytesPerformance() {
byte[] data = new byte[SIZE];
new java.util.Random().nextBytes(data);
BitString bitString = new BitString(SIZE);
long startTime = System.nanoTime();
long endTime = System.nanoTime();
long duration = endTime - startTime;
System.out.println("Read Uint performance: " + duration / 1_000_000 + " ms");

bitString.writeBytes(data);
assertTrue("Test should complete in less than 300 ms", duration < 300_000_000);
}

long endTime = System.nanoTime();
long duration = endTime - startTime;
System.out.println("Write Bytes performance: " + duration / 1_000_000 + " ms");
@Test
public void testWriteBytesPerformance() {
byte[] data = new byte[SIZE];
new java.util.Random().nextBytes(data);
BitString bitString = new BitString(SIZE);
long startTime = System.nanoTime();

assertTrue("Test should complete in less than 300 ms", duration < 300_000_000);
}
bitString.writeBytes(data);

@Test
public void testReadBytesPerformance() {
byte[] data = new byte[SIZE];
new java.util.Random().nextBytes(data);
BitString bitString = new BitString(SIZE);
bitString.writeBytes(data);
long endTime = System.nanoTime();
long duration = endTime - startTime;
System.out.println("Write Bytes performance: " + duration / 1_000_000 + " ms");

long startTime = System.nanoTime();
assertTrue("Test should complete in less than 300 ms", duration < 300_000_000);
}

bitString.readBytes(SIZE * 8);
@Test
public void testReadBytesPerformance() {
byte[] data = new byte[SIZE];
new java.util.Random().nextBytes(data);
BitString bitString = new BitString(SIZE);
bitString.writeBytes(data);

long endTime = System.nanoTime();
long duration = endTime - startTime;
System.out.println("Read Bytes performance: " + duration / 1_000_000 + " ms");
long startTime = System.nanoTime();

assertTrue("Test should complete in less than 300 ms", duration < 300_000_000);
}
bitString.readBytes(SIZE * 8);

@Test
public void testWriteUint() {
BitString bitString = new BitString(SIZE);
long endTime = System.nanoTime();
long duration = endTime - startTime;
System.out.println("Read Bytes performance: " + duration / 1_000_000 + " ms");

BigInteger number = new BigInteger("12345678901234567890");
int bitLength = SIZE;
assertTrue("Test should complete in less than 300 ms", duration < 300_000_000);
}

long startTime = System.nanoTime();
bitString.writeUint(number, bitLength);
@Test
public void testWriteUint() {
BitString bitString = new BitString(SIZE);

BigInteger result = bitString.readUint(bitLength);
BigInteger number = new BigInteger("12345678901234567890");
int bitLength = SIZE;

long endTime = System.nanoTime();
long duration = endTime - startTime;
System.out.println("Read Bytes performance: " + duration / 1_000_000 + " ms");
assertTrue("Test should complete in less than 300 ms", duration < 300_000_000);
long startTime = System.nanoTime();
bitString.writeUint(number, bitLength);

assertEquals(number, result);
}
BigInteger result = bitString.readUint(bitLength);

long endTime = System.nanoTime();
long duration = endTime - startTime;
System.out.println("Read Bytes performance: " + duration / 1_000_000 + " ms");
assertTrue("Test should complete in less than 300 ms", duration < 300_000_000);

assertEquals(number, result);
}
}
Loading

0 comments on commit ddceb2f

Please sign in to comment.