kenenet 0.8.6__py3-none-any.whl → 0.8.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
kenenet/__init__.py CHANGED
@@ -1,6 +1,8 @@
1
- import inspect, sys, zhmiscellany, keyboard, mss, time, linecache, types, os, random, pyperclip, inspect, datetime, atexit
1
+ import inspect, sys, zhmiscellany, keyboard, mss, time, linecache, types, os, random, pyperclip, inspect, datetime, atexit, re
2
2
  import numpy as np
3
3
  from PIL import Image
4
+ from collections import defaultdict
5
+
4
6
  from pydub import AudioSegment
5
7
  from pydub.playback import play
6
8
  import random
@@ -48,7 +50,7 @@ def timer(clock=1):
48
50
  elapsed = time.time() - timings[clock][0]
49
51
  frame = inspect.currentframe().f_back
50
52
  lineno = frame.f_lineno
51
- if timer == 1:
53
+ if clock == 1:
52
54
  quick_print(f'Timer took \033[97m{elapsed}\033[0m seconds', f'{lineno}-{timings[clock][1]}')
53
55
  else:
54
56
  quick_print(f'Timer {clock} took \033[97m{elapsed}\033[0m seconds', f'{lineno}-{timings[clock][1]}')
@@ -267,8 +269,6 @@ def load_audio(mp3_path):
267
269
  _ray_init_thread.join()
268
270
  return zhmiscellany.processing.synchronous_class_multiprocess(AudioPlayer, mp3_path)
269
271
 
270
- import time
271
-
272
272
  def time_func(func, loop=10000, *args, **kwargs):
273
273
  func_name = getattr(func, '__name__', repr(func))
274
274
  frame = inspect.currentframe().f_back
@@ -279,7 +279,125 @@ def time_func(func, loop=10000, *args, **kwargs):
279
279
  elapsed = time.time() - start
280
280
  quick_print(f'{loop:,}x {func_name} took {elapsed}', lineno)
281
281
  return elapsed
282
+
283
+
284
+
285
+ _timings = defaultdict(list)
286
+ _block_timings = defaultdict(float)
287
+ _current_context = None
288
+ _line_start_time = None
289
+ _stack = []
290
+
291
+
292
+ def time_code(label=None):
293
+ global _current_context, _timings, _line_start_time, _block_timings, _stack
294
+
295
+ # Get the frame of the caller
296
+ frame = inspect.currentframe().f_back
297
+ filename = frame.f_code.co_filename
282
298
 
299
+ if _current_context is None:
300
+ # First call - start timing
301
+ _current_context = label or f"timing_{len(_timings)}"
302
+ quick_print(f"⏱️ Starting timing for context: {_current_context}")
303
+ _line_start_time = time.time()
304
+ _block_timings.clear()
305
+ _stack = []
306
+
307
+ # Define the trace function
308
+ def trace_function(frame, event, arg):
309
+ global _line_start_time, _stack
310
+
311
+ # Track function calls and returns
312
+ if event == 'call':
313
+ func_name = frame.f_code.co_name
314
+ if func_name != 'time_code':
315
+ _stack.append((func_name, time.time()))
316
+ return trace_function
317
+
318
+ elif event == 'return':
319
+ if _stack:
320
+ func_name, start_time = _stack.pop()
321
+ elapsed = time.time() - start_time
322
+ _block_timings[f"Function: {func_name}"] += elapsed
323
+ return None
324
+
325
+ elif event == 'line':
326
+ # Get current line information
327
+ lineno = frame.f_lineno
328
+ line_content = linecache.getline(frame.f_code.co_filename, lineno).strip()
329
+
330
+ # Skip empty lines or comments
331
+ if not line_content or line_content.startswith('#'):
332
+ return trace_function
333
+
334
+ # Check if we should stop tracing
335
+ if "time_code" in line_content and _current_context is not None:
336
+ # This might be the ending call, let's continue execution
337
+ return trace_function
338
+
339
+ # Record elapsed time since last line
340
+ current_time = time.time()
341
+ if _line_start_time is not None:
342
+ elapsed = current_time - _line_start_time
343
+ _timings[_current_context].append((lineno, line_content, elapsed))
344
+
345
+ # Track loop timings
346
+ if re.match(r'\s*(for|while)\s+', line_content):
347
+ loop_id = f"Loop at line {lineno}: {line_content[:40]}{'...' if len(line_content) > 40 else ''}"
348
+ _block_timings[loop_id] += elapsed
349
+
350
+ # Set new start time for next line
351
+ _line_start_time = current_time
352
+
353
+ return trace_function
354
+
355
+ # Start tracing
356
+ sys.settrace(trace_function)
357
+
358
+ else:
359
+ sys.settrace(None)
360
+ context = _current_context
361
+ _current_context = None
362
+ _line_start_time = None
363
+
364
+ if not _timings[context]:
365
+ quick_print(f"No timing data collected for context: {context}")
366
+ return
367
+
368
+ sorted_timings = sorted(_timings[context], key=lambda x: x[2], reverse=True)
369
+
370
+ quick_print(f"\n⏱️ Detailed timing results for context: {context}")
371
+ quick_print("-" * 80)
372
+ quick_print(f"{'Line':>6} | {'Time':>12} | Code")
373
+ quick_print("-" * 80)
374
+
375
+ for lineno, line_content, elapsed in sorted_timings:
376
+ quick_print(f"{lineno:6d} | {elapsed:12.6f} | {line_content}")
377
+
378
+ quick_print("-" * 80)
379
+ total_time = sum(elapsed for _, _, elapsed in _timings[context])
380
+ quick_print(f"Total execution time: {total_time * 1000:.6f} ms")
381
+
382
+ if _block_timings:
383
+ quick_print("\n📊 Summary of function and loop execution times:")
384
+ quick_print("-" * 80)
385
+ quick_print(f"{'Block Type':^40} | {'Time':>12} | {'% of Total':>10}")
386
+ quick_print("-" * 80)
387
+
388
+ # Sort block timings by time
389
+ sorted_blocks = sorted(_block_timings.items(), key=lambda x: x[1], reverse=True)
390
+
391
+ for block, elapsed in sorted_blocks:
392
+ percentage = (elapsed / total_time) * 100 if total_time > 0 else 0
393
+ quick_print(f"{block[:40]:40} | {elapsed:12.6f} | {percentage:10.2f}%")
394
+
395
+ quick_print("-" * 80)
396
+
397
+ # Clear the timing data for this context
398
+ del _timings[context]
399
+ _block_timings.clear()
400
+
283
401
  class k:
284
402
  pass
285
403
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kenenet
3
- Version: 0.8.6
3
+ Version: 0.8.8
4
4
  Summary: dude what the fuck even is this package
5
5
  Home-page: https://www.youtube.com/@KiddyKene
6
6
  Author: kiddykene
@@ -0,0 +1,5 @@
1
+ kenenet/__init__.py,sha256=Zv3A0UQ3NsHqM7OxO0cII3NHmlUvzhArwKxuX2Ch4Nk,16220
2
+ kenenet-0.8.8.dist-info/METADATA,sha256=tHUmAN5bqgsw9FMtMs9u-1ehqHoTg8ekwBmexpfp_9A,633
3
+ kenenet-0.8.8.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
4
+ kenenet-0.8.8.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
5
+ kenenet-0.8.8.dist-info/RECORD,,
@@ -1,5 +0,0 @@
1
- kenenet/__init__.py,sha256=b_mtEwWLKKleN6D6Qto6dyv8LDtPTV5f3D8jP0eR_NA,11460
2
- kenenet-0.8.6.dist-info/METADATA,sha256=ClRjCpmI00kdm-RvJsat-Z2eiKGwPaQzBVmgJ0V1q3k,633
3
- kenenet-0.8.6.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
4
- kenenet-0.8.6.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
5
- kenenet-0.8.6.dist-info/RECORD,,