Переглянути джерело

Larger blocks. Give a percentage of set/clear

dstromberg 13 роки тому
батько
коміт
5fb9908837
1 змінених файлів з 7 додано та 5 видалено
  1. 7 5
      count-bits

+ 7 - 5
count-bits

@@ -1,13 +1,15 @@
-#!/usr/bin/python
+#!/usr/local/pypy-1.6/bin/pypy
 
 import sys
 
-set_bits = 0
+total_bits = 0
+bits_set = 0
 
 while True:
-	block = sys.stdin.read(2**16)
+	block = sys.stdin.read(2**19)
 	if not block:
 		break
+	total_bits += len(block) * 8
 	#print('got block of length %d' % len(block))
 	for char in block:
 		byte = ord(char)
@@ -17,7 +19,7 @@ while True:
 			#print('checking mask %d' % bitmask)
 			if byte & bitmask != 0:
 				#print('adding 1 to count')
-				set_bits += 1
+				bits_set += 1
 
-print(set_bits)
+print('%s set, %s present, %6.2f%%' % (bits_set, total_bits, bits_set * 100.0 / total_bits))