This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fred | Key | MC Guimê | ||
---|---|---|---|---|
Amanda | 250 | 120 | 10 | |
Bruno | 50 | 150 | 200 | |
Tina | 150 | 110 | 170 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
@dataclass | |
class Ref: | |
"""Representação de uma variável. | |
Se ela não possuir um valor ainda, é dita livre; se não, ela está ligada.""" | |
name: str | |
value: any = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker run \ | |
--memory 100m --memory-swap 100m \ | |
-e FILENAME=big_file_1m.txt \ | |
-e MAX_MEMORY_OCCUPANCY=0.66 \ | |
-e REPORT_INTERVAL=1 \ | |
big_file_counter | gzip -c > output.log.gz | |
approx usage kernel usage total cache total rss total swap inactive file working set limit | |
9.16 MiB 600.00 KiB 2.03 MiB 6.48 MiB 0.00 B 1.80 MiB 7.36 MiB 100.00 MiB | |
40.56 MiB 656.00 KiB 2.03 MiB 37.87 MiB 0.00 B 1.80 MiB 38.76 MiB 100.00 MiB |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def merge_files(filenames): | |
# Abre um arquivo temporário de forma segura | |
fd, tempname = tempfile.mkstemp(text=True) | |
try: | |
target = os.fdopen(fd, mode='w') | |
# Abre todos os arquivos temporários. | |
# FileState é um wrapper que guarda qual foi a última chave/valor lida | |
files = [FileState(filename) for filename in filenames] | |
[f.open() for f in files] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def memory_working_set() -> int: | |
usage = memory_usage() | |
inactive = memory_stats()['inactive_file'] | |
return usage - inactive |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def memory_usage() -> int: | |
with open('/sys/fs/cgroup/memory/memory.memsw.usage_in_bytes') as f: | |
return int(f.read()) | |
def memory_limit() -> int: | |
with open('/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes') as f: | |
return int(f.read()) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_counter_size(c: Counter) -> int: | |
size = sys.getsizeof(c) | |
size += sum(sys.getsizeof(key) for key in c) | |
return size |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gc | |
import sys | |
def get_transitive_size(obj): | |
stack = [obj] | |
size = 0 | |
seen = set() | |
while stack: | |
o = stack.pop() | |
if isinstance(o, type): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_file(num_elements: int, size: int, filename: str) -> int: | |
with open(filename, 'w') as f: | |
total = 0 | |
while total < size: | |
value = random.randrange(num_elements) | |
total += f.write(f'{value}\n') | |
return total |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
c = Counter() | |
with open('big_file.txt') as f: | |
for line in f: | |
c[line[:-1]] += 1 # Remove newline from line | |
for key, count in c.most_common(): | |
print(f'{key} - {count}') |
NewerOlder