---- -- File:: zip_profile.rbs -- Description:: Profile ZIP building/extraction operations. -- -- Author:: David Muir -- Date:: 20 September 2010 -- ----------------------------------------------------------------------------- -- Uses ----------------------------------------------------------------------------- -- None ----------------------------------------------------------------------------- -- File Globals ----------------------------------------------------------------------------- local iterations = 10 local compress = false local zip_filename = "x:\\gta5\\build\\dev\\independent\\levels\\gta5\\vehicles.zip" local out_filename = "x:\\gta5\\build\\dev\\independent\\levels\\gta5\\vehicles.copy.zip" local temp_dir = "c:\\temp\\" local mount_point = "zip:/" ----------------------------------------------------------------------------- -- Functions ----------------------------------------------------------------------------- -- -- Parse any unit test option command line parameters. -- function set_parameters( ) in_iterations = get_param( "iterations" ) if ( in_iterations ~= nil ) then iterations = 0 + in_iterations end in_compress = get_param( "compress" ) if ( in_compress ~= nil ) then compress = ( "true" == in_compress ) end print( "Test Parameters" ) print( "iterations = " .. iterations ) if ( compress ) then print( "compress = true" ) else print( "compress = false" ) end end -- -- Run one test iteration on a single ZIP file. Returns three values; the -- first being the file find time, then extract time, third being the rebuild time. -- function test_zip( filename ) -- Extract mount_zip( filename, mount_point ) local find_start = os.clock() local files = find_files( mount_point .. "*.*" ) local find_duration = ( os.clock() - find_start ) local extract_start = os.clock() for key, value in files do local file = get_filename_from_path( value ) copy_file( mount_point .. file, temp_dir .. file ) end unmount_zip( filename ) local extract_duration = ( os.clock() - extract_start ) -- Rebuild local rebuild_start = os.clock() if ( compress ) then start_zip( ) else start_uncompressed_zip( ) end for key, value in files do local file = get_filename_from_path( value ) add_to_zip( temp_dir .. file ) end save_zip( out_filename ) close_zip() local rebuild_duration = ( os.clock() - rebuild_start ) return find_duration, extract_duration, rebuild_duration end -- -- Return average of all values in specified array. -- function average( data, count ) local total = 0 for i = 1, count do total = total + data[i] end return ( total / count ) end -- -- Return the minimum and maximum of all values in specified array. function maxmin( data, count ) local min = 99999999 local max = -99999999 for i = 1, count do if ( data[i] < min ) then min = data[i] end if ( data[i] > max ) then max = data[i] end end return min, max end ----------------------------------------------------------------------------- -- Entry-Point ----------------------------------------------------------------------------- set_parameters() create_leadingpath( temp_dir .. "blah.txt" ) local index = 0 local find_durations = {} local extract_durations = {} local rebuild_durations = {} for index = 1, iterations do f, e, b = test_zip( zip_filename ) find_durations[index] = f extract_durations[index] = e rebuild_durations[index] = b display( string.format( "[%d] Find duration (s) : %.3f", index, f ) ) display( string.format( "[%d] Extract duration (s): %.3f", index, e ) ) display( string.format( "[%d] Rebuild duration (s): %.3f", index, b ) ) end print( "Find Results:" ) min, max = maxmin( find_durations, iterations ) print( string.format( "\tAverage duration (s): %.3f", average( find_durations, iterations ) ) ) print( string.format( "\tMinimum duration (s): %.3f", min ) ) print( string.format( "\tMaximum duration (s): %.3f", max ) ) print( "Extraction Results:" ) min, max = maxmin( extract_durations, iterations ) print( string.format( "\tAverage duration (s): %.3f", average( extract_durations, iterations ) ) ) print( string.format( "\tMinimum duration (s): %.3f", min ) ) print( string.format( "\tMaximum duration (s): %.3f", max ) ) print( "Rebuild Results:" ) min, max = maxmin( rebuild_durations, iterations ) print( string.format( "\tAverage duration (s): %.3f", average( rebuild_durations, iterations ) ) ) print( string.format( "\tMinimum duration (s): %.3f", min ) ) print( string.format( "\tMaximum duration (s): %.3f", max ) ) -- rpf_profile.rbs