- Timestamp:
- 02/03/13 21:22:14 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Tests/JAVA/test/src/main/java/test/threads/experiment2/Main.java
r577 r578 18 18 public class Main { 19 19 private static final boolean ASYNC = Boolean.getBoolean( "async" ); 20 private static final boolean PREDIC ABLE_SCAN = Boolean.getBoolean( "predictable" );20 private static final boolean PREDICTABLE_SCAN = Boolean.getBoolean( "predictable" ); 21 21 22 22 private static final int RUNS = Integer.getInteger( "runs", 32 ); 23 23 private static final int TURNS = Integer.getInteger( "turns", 1 << 20 ); 24 24 25 private static final int REPOSITORY_SIZE_EXP = Integer.getInteger( "repository-size-exp", 15 ); 26 private static final int REPOSITORY_SIZE = 1 << REPOSITORY_SIZE_EXP; 27 private static final int READ_PER_MESSAGE = 128; 28 private static final int READ_STEP = 1025; 25 private static final int DATA_SIZE_EXP = Integer.getInteger( "data-size-exp", 12 ); 26 private static final int DATA_SIZE = 1 << DATA_SIZE_EXP; 27 28 29 private static final int OPS_PER_MESSAGE = 128; 30 private static final int OPS_ARRAY_STEP = 8; 29 31 30 32 private static final ThreadAffinityService AFFINITY_SERVICE = ThreadAffinityUtils.defaultAffinityService(); … … 33 35 public static void main( final String[] args ) { 34 36 System.out.printf( 35 "%s, Repo: double[%d], %d reads/msg, %s\n" +37 "%s, data: double[%d], %d reads/msg, %s\n" + 36 38 "\t%d runs by %d messages each\n", 37 39 ( ASYNC ? "ASYNC" : "SYNC" ), 38 REPOSITORY_SIZE, READ_PER_MESSAGE,39 PREDIC ABLE_SCAN ? "step: " + READ_STEP : "random",40 DATA_SIZE, OPS_PER_MESSAGE, 41 PREDICTABLE_SCAN ? "step: " + OPS_ARRAY_STEP : "random", 40 42 RUNS, TURNS 41 43 ); 42 44 43 45 44 final double[] repositoryA = new double[REPOSITORY_SIZE];45 Arrays.fill( repositoryA, 1.0 );46 final double[] repositoryB = new double[REPOSITORY_SIZE];47 Arrays.fill( repositoryB, 1.0 );48 49 50 final Phase a = new Phase( repositoryA );51 final Phase b = new Phase( repositoryB );46 final double[] dataA = new double[DATA_SIZE]; 47 Arrays.fill( dataA, 1.0 ); 48 final double[] dataB = new double[DATA_SIZE]; 49 Arrays.fill( dataB, 1.0 ); 50 51 52 final Phase a = new Phase( dataA ); 53 final Phase b = new Phase( dataB ); 52 54 53 55 final Function<Message, Message> function; … … 86 88 } 87 89 88 private static void putStressOnMemory( final double[] repository,90 private static void putStressOnMemory( final double[] array, 89 91 final int offset, 90 92 final double amount ) { 91 if( PREDIC ABLE_SCAN ) {92 for( int i = 0; i < READ_PER_MESSAGE; i++ ) {93 final int index = ( i * READ_STEP + offset ) % REPOSITORY_SIZE;94 repository[index] += amount;93 if( PREDICTABLE_SCAN ) { 94 for( int i = 0; i < OPS_PER_MESSAGE; i++ ) { 95 final int index = ( i * OPS_ARRAY_STEP + offset ) % DATA_SIZE; 96 array[index] += amount; 95 97 } 96 98 } else { 97 99 int index = offset; 98 for( int i = 0; i < READ_PER_MESSAGE; i++ ) {99 index = Math.abs( index * offset ) % REPOSITORY_SIZE;100 repository[index] += amount;100 for( int i = 0; i < OPS_PER_MESSAGE; i++ ) { 101 index = Math.abs( index * offset ) % DATA_SIZE; 102 array[index] += amount; 101 103 } 102 104 } … … 128 130 final double amountStep = 1.0 / turns; 129 131 for( int turn = 0; turn < turns; turn++ ) { 130 message.index = ( message.index + 1 ) / REPOSITORY_SIZE;132 message.index = ( message.index + 1 ) / DATA_SIZE; 131 133 message.amount += amountStep; 132 134 f.apply( message ); … … 173 175 public static class Phase implements Function<Message, Message> { 174 176 175 private final double[] repository;176 177 public Phase( final double[] repository) {178 this. repository = repository;177 private final double[] data; 178 179 public Phase( final double[] data ) { 180 this.data = data; 179 181 } 180 182 … … 183 185 final double amount = message.amount; 184 186 final int offset = message.index; 185 putStressOnMemory( repository, offset, amount );187 putStressOnMemory( data, offset, amount ); 186 188 //actually, message just pass through 187 189 return message;
Note: See TracChangeset
for help on using the changeset viewer.