99import os
1010import sys
1111import json
12- import timeit
13- import concurrent .futures
14- from concurrent .futures import ThreadPoolExecutor
12+ import time
1513
1614from knack .cli import CLI
1715from knack .commands import CLICommandsLoader
@@ -322,14 +320,14 @@ def _update_command_table_from_modules(args, command_modules=None):
322320 except ImportError as e :
323321 logger .warning (e )
324322
325- start_time = timeit . default_timer ()
323+ start_time = time . perf_counter ()
326324 logger .debug ("Loading command modules..." )
327325 results = self ._load_modules (args , command_modules )
328326
329327 count , cumulative_group_count , cumulative_command_count = \
330328 self ._process_results_with_timing (results )
331329
332- total_elapsed_time = timeit . default_timer () - start_time
330+ total_elapsed_time = time . perf_counter () - start_time
333331 # Summary line
334332 logger .debug (self .item_format_string ,
335333 "Total ({})" .format (count ), total_elapsed_time ,
@@ -404,7 +402,7 @@ def _filter_modname(extensions):
404402 # Add to the map. This needs to happen before we load commands as registering a command
405403 # from an extension requires this map to be up-to-date.
406404 # self._mod_to_ext_map[ext_mod] = ext_name
407- start_time = timeit . default_timer ()
405+ start_time = time . perf_counter ()
408406 extension_command_table , extension_group_table , extension_command_loader = \
409407 _load_extension_command_loader (self , args , ext_mod )
410408 import_extension_breaking_changes (ext_mod )
@@ -427,7 +425,7 @@ def _filter_modname(extensions):
427425 self .command_table .update (extension_command_table )
428426 self .command_group_table .update (extension_group_table )
429427
430- elapsed_time = timeit . default_timer () - start_time
428+ elapsed_time = time . perf_counter () - start_time
431429 logger .debug (self .item_ext_format_string , ext_name , elapsed_time ,
432430 len (extension_group_table ), len (extension_command_table ),
433431 ext_dir )
@@ -667,6 +665,8 @@ def load_arguments(self, command=None):
667665
668666 def _load_modules (self , args , command_modules ):
669667 """Load command modules using ThreadPoolExecutor with timeout protection."""
668+ import concurrent .futures
669+ from concurrent .futures import ThreadPoolExecutor
670670 from azure .cli .core .commands import BLOCKED_MODS
671671
672672 results = []
@@ -708,10 +708,10 @@ def _load_single_module(self, mod, args):
708708 from azure .cli .core .commands import _load_module_command_loader
709709 import traceback
710710 try :
711- start_time = timeit . default_timer ()
711+ start_time = time . perf_counter ()
712712 module_command_table , module_group_table , command_loader = _load_module_command_loader (self , args , mod )
713713 import_module_breaking_changes (mod )
714- elapsed_time = timeit . default_timer () - start_time
714+ elapsed_time = time . perf_counter () - start_time
715715 return ModuleLoadResult (mod , module_command_table , module_group_table , elapsed_time , command_loader = command_loader )
716716 except Exception as ex : # pylint: disable=broad-except
717717 tb_str = traceback .format_exc ()
@@ -1227,7 +1227,7 @@ def update(self, command_table):
12271227
12281228 :param command_table: The command table built by azure.cli.core.MainCommandsLoader.load_command_table
12291229 """
1230- start_time = timeit . default_timer ()
1230+ start_time = time . perf_counter ()
12311231 self .INDEX [self ._COMMAND_INDEX_VERSION ] = __version__
12321232 self .INDEX [self ._COMMAND_INDEX_CLOUD_PROFILE ] = self .cloud_profile
12331233 from collections import defaultdict
@@ -1242,7 +1242,7 @@ def update(self, command_table):
12421242 if module_name not in index [top_command ]:
12431243 index [top_command ].append (module_name )
12441244
1245- elapsed_time = timeit . default_timer () - start_time
1245+ elapsed_time = time . perf_counter () - start_time
12461246 self .INDEX [self ._COMMAND_INDEX ] = index
12471247
12481248 self .update_extension_index (command_table )
0 commit comments