QVector< float > data( 1024, 0.0f ); float * values = data.data(); int int_count = data.count(); for ( int i = 0; i < 40; ++i ) { quint64 count = quint64( 1 ) << i; qDebug() << "Start tests:" << i << "-" << count << "iterations"; QTime timing; timing.start(); for ( quint64 iter = 0; iter < count; ++iter ) { for ( int i = 0; i < int_count; ++i ) { values[ i ] = static_cast< float >( iter + i ); } } qDebug() << timing.elapsed() << "for container[ i ]"; timing.restart(); for ( quint64 iter = 0; iter < count; ++iter ) { for ( int i = 0; i < int_count; ++i ) { *( values + i ) = static_cast< float >( iter + i ); } } qDebug() << timing.elapsed() << "for *( array + i )"; } } return 0;
Start tests: 16 - 65536 iterations 612 for container[ i ] 610 for *( array + i ) Start tests: 17 - 131072 iterations 1235 for container[ i ] 1230 for *( array + i ) Start tests: 18 - 262144 iterations 2473 for container[ i ] 2452 for *( array + i ) Start tests: 19 - 524288 iterations 4920 for container[ i ] 4903 for *( array + i ) Start tests: 20 - 1048576 iterations 9810 for container[ i ] 9820 for *( array + i )
Start tests: 16 - 65536 iterations 613 for container[ i ] 690 for *( array + i ) Start tests: 17 - 131072 iterations 1232 for container[ i ] 1390 for *( array + i ) Start tests: 18 - 262144 iterations 2455 for container[ i ] 2775 for *( array + i ) Start tests: 19 - 524288 iterations 4908 for container[ i ] 5612 for *( array + i ) Start tests: 20 - 1048576 iterations 9818 for container[ i ] 11183 for *( array + i )