Differences

This shows you the differences between two versions of the page.

Link to this comparison view

ep:labs:01:contents:ex3 [2019/09/22 15:42]
radu.mantu removed
— (current)
Line 1: Line 1:
-==== T03. [20p] Zip with compression levels ==== 
-The **zip** command is used for compression and file packaging under Linux/Unix operating system. It provides 10 levels of compression,​ where: 
-  * **level 0** : provides no compression,​ only packaging 
-  * **level 6** : used as default compression level 
-  * **level 9** : provides maximum compression 
- 
-<code bash> 
-$ zip -5 file.zip file.txt 
-</​code>​ 
- 
-=== [15p] Task A - Measurements === 
-Write a script to measure the compression rate and the time required for each level. Use the following files: 
-  * two largest bitmaps from [[https://​www.fileformat.info/​format/​bmp/​sample/​index.htm|here]] 
-  * this large text file [[https://​norvig.com/​big.txt|here]] 
- 
-=== [5p] Task B - Plot === 
-Fill the data you obtained into the python3 script in {{:​ep:​labs:​plot.zip|plot.zip}}. \\ 
-Make sure you have **python3** and **python3-matplotlib** installed. 
- 
-<​solution -hidden> 
-**Task A:** 
- 
-<code bash> 
-#!/bin/bash 
- 
-# clean up base files directory and archives 
-rm -rf file* 
-mkdir files 
- 
-# download some large files (2 images, 1 text) 
-( cd files \ 
-; printf "​\033[33mStarting file download...\n\tPart 1/3 ... " \ 
-; wget -q -O image_1.bmp ​  ​https://​www.fileformat.info/​format/​bmp/​sample/​4cb74cda027a43f3b278c05c3770950f/​download \ 
-; printf "​\033[32mdone\n\t\033[33mPart 2/3 ... " \ 
-; wget -q -O image_2.bmp ​  ​https://​www.fileformat.info/​format/​bmp/​sample/​1d71eff930af4773a836a32229fde106/​download \ 
-; printf "​\033[32mdone\n\t\033[33mPart 3/3 ... " \ 
-; wget -q -O text_file.txt https://​norvig.com/​big.txt \ 
-; printf "​\033[32mdone\n\033[0m"​ 
-) 
- 
-# archive folder 
-for i in $(seq 0 9); do 
- if [ ${i} -eq 6 ]; then 
- printf "​\n\033[31m >>>​ Default compression level <<<"​ 
- fi 
- 
- printf "​\n\033[33mStarting:​ \033[1mzip -r -${i} files-${i}.zip files/​\n\033[0m"​ 
- 
- time zip -r -${i} files-$i.zip files 
-done 
-</​code>​ 
- 
-**Task B:** 
-<code python> 
-#​!/​usr/​bin/​python3 
- 
-import matplotlib.pyplot as plt 
- 
- 
-def main(): 
- # TODO: for each compression level in {0, 1, ..., 9}: 
- # fill real_time [ms] 
- # fill archive_size [bytes] 
- level ​       = list(range(10)) 
- real_time ​   = [ 47, 251, 278, 356, 350, 489, 688, 810, 1027, 1074 ] 
- archive_size = [ 12193688, 5762873, 5570296, 5401227, 5307842, 
-                         ​5185863, ​ 5130121, 5118616, 5111763, 5111482 ] 
- 
- archive_size = [it / 1024 for it in archive_size] 
- 
- # plot data 
- fix, axs = plt.subplots(2) 
- 
- axs[0].plot(level,​ real_time, ​   '​bo-'​) 
- axs[1].plot(level,​ archive_size,​ '​ro-'​) 
- 
- axs[0].set_xticks(level) 
- axs[1].set_xticks(level) 
- 
- axs[0].grid(True,​ which='​both'​) 
- axs[1].grid(True,​ which='​both'​) 
- 
- axs[0].set_xlabel('​Compression level'​) 
- axs[1].set_xlabel('​Compression level'​) 
- 
- axs[0].set_ylabel('​Time [ms]') 
- axs[1].set_ylabel('​Archive size [byte]'​) 
- 
- plt.show() 
- 
- 
-if __name__ == '​__main__':​ 
- main() 
-</​code>​ 
-</​solution>​ 
  
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0