Index: wp-admin/includes/ajax-actions.php
===================================================================
--- wp-admin/includes/ajax-actions.php	(revision 23226)
+++ wp-admin/includes/ajax-actions.php	(working copy)
@@ -1852,6 +1852,17 @@
 	$posts = array_map( 'wp_prepare_attachment_for_js', $query->posts );
 	$posts = array_filter( $posts );
 
+	// Timing code start
+	global $attachment_timing_array;
+	
+	if ( ! empty( $attachment_timing_array ) ) {
+		$count = count( $attachment_timing_array );
+		$avg_time = round( 1000 * array_sum( $attachment_timing_array ) / $count, 3 ); // (ms)
+		$text = "Avg time " . $avg_time . " ms based on " . $count . " thumbnails or medium-sized images.\r\n";
+		file_put_contents( '../timing_dump.txt', $text , FILE_APPEND );
+	}
+	// Timing code end
+	
 	wp_send_json_success( $posts );
 }
 
Index: wp-includes/media.php
===================================================================
--- wp-includes/media.php	(revision 23226)
+++ wp-includes/media.php	(working copy)
@@ -1393,8 +1393,25 @@
 				// We have the actual image size, but might need to further constrain it if content_width is narrower.
 				// This is not necessary for thumbnails and medium size.
 				if ( 'thumbnail' == $size || 'medium' == $size ) {
+					// Timer start
+					$time_start = microtime( true );
+					
+					/* Option 1: Original 3.5.0 code
 					$width = $size_meta['width'];
 					$height = $size_meta['height'];
+					*/
+					
+					/* Option 2: Proposed 3.5.1 code */
+					list( $width, $height ) = image_constrain_size_for_editor( $size_meta['width'], $size_meta['height'], $size, 'edit' );
+					
+					/* Option 3: Equivalent 3.4 code
+					list( $img_src, $width, $height ) = image_downsize( $attachment->ID, $size );
+					*/
+					
+					// Timer end
+					$time_end = microtime( true );
+					global $attachment_timing_array;
+					$attachment_timing_array[] = $time_end - $time_start;
 				} else {
 					list( $width, $height ) = image_constrain_size_for_editor( $size_meta['width'], $size_meta['height'], $size, 'edit' );
 				}
