#!/usr/bin/env python3 """ Basic Performance Test for Curriculum Assistant Tests core concepts without external dependencies """ import time import os from pathlib import Path import json class BasicCurriculumTest: def __init__(self): self.response_cache = {} self.sample_data = { "loops": { "filename": "Week 6 lesson.pptx (1).pdf", "page": 1, "content": "Loops are programming constructs that solve the problem of repetition. Instead of writing hundreds of print statements to count from 1 to 100, loops allow you to accomplish the same task with just a few lines of code." }, "variables": { "filename": "Week 4 Lesson.pptx (2).pdf", "page": 2, "content": "Variables are containers that store data values. They allow you to save and reuse information in your programs." }, "functions": { "filename": "Week 5 lesson.pptx.pdf", "page": 3, "content": "Functions are reusable blocks of code that perform specific tasks. They help organize code and avoid repetition." } } print("โœ… Basic test initialized") def simple_search(self, query): """Simple keyword-based search""" start_time = time.time() # Check cache if query in self.response_cache: print(f"โœ… Cache hit! Response time: {time.time() - start_time:.3f}s") return self.response_cache[query] # Simple keyword search query_lower = query.lower() results = [] for topic, data in self.sample_data.items(): if query_lower in topic.lower() or query_lower in data['content'].lower(): results.append({ 'topic': topic, 'filename': data['filename'], 'page': data['page'], 'content': data['content'], 'score': data['content'].lower().count(query_lower) }) # Sort by relevance results.sort(key=lambda x: x['score'], reverse=True) # Generate response if results: best_result = results[0] response = f"๐Ÿ“„ Found in: {best_result['filename']} - Page {best_result['page']}\n\n" response += f"Topic: {best_result['topic']}\n" response += f"Content: {best_result['content']}\n\n" response += f"Found {len(results)} relevant topics" else: response = f"No relevant content found for '{query}'" # Cache result self.response_cache[query] = response response_time = time.time() - start_time print(f"โœ… Response generated in {response_time:.3f} seconds") return response def test_performance(): """Run performance tests""" print("๐Ÿš€ Starting Basic Performance Test...") # Initialize start_time = time.time() chatbot = BasicCurriculumTest() init_time = time.time() - start_time print(f"โœ… Initialization time: {init_time:.3f} seconds") # Test queries test_queries = [ "loops", "variables", "functions", "programming", "for loop", "while loop" ] print(f"\n๐Ÿงช Testing {len(test_queries)} queries...") total_time = 0 for i, query in enumerate(test_queries, 1): print(f"\n--- Test {i}/{len(test_queries)}: '{query}' ---") start_time = time.time() response = chatbot.simple_search(query) query_time = time.time() - start_time total_time += query_time print(f"Response time: {query_time:.3f}s") print(f"Response length: {len(response)} characters") print(f"Cache size: {len(chatbot.response_cache)} entries") # Show first 150 chars of response print(f"Response preview: {response[:150]}...") # Summary avg_time = total_time / len(test_queries) print(f"\n๐Ÿ“Š Performance Summary:") print(f"Total time: {total_time:.3f}s") print(f"Average response time: {avg_time:.3f}s") print(f"Initialization time: {init_time:.3f}s") print(f"Cache hits: {len([q for q in test_queries if q in chatbot.response_cache])}") # Performance rating if avg_time < 0.001: rating = "๐Ÿš€ EXCELLENT (< 1ms)" elif avg_time < 0.01: rating = "โœ… GOOD (< 10ms)" elif avg_time < 0.1: rating = "โš ๏ธ ACCEPTABLE (< 100ms)" else: rating = "โŒ SLOW (> 100ms)" print(f"Performance rating: {rating}") # Comparison with 10-minute response time if avg_time < 600: # 10 minutes = 600 seconds improvement = 600 / avg_time if avg_time > 0 else float('inf') print(f"๐Ÿš€ This is {improvement:.0f}x faster than the 10-minute response time!") else: print("โŒ This is still slower than the 10-minute response time") if __name__ == "__main__": test_performance()